使用 gdb 打印一个 time_t 变量
Using gdb to print a time_t variable
我想从 gdb 打印一些信息,但不知道如何打印。我习惯了 p/s p/x 格式。但是不知道下面的情况怎么办。
#include<iostream>
#include<climits>
#include <stdio.h>
#include <time.h>
#include <stdint.h>
using namespace std;
int main()
{
time_t dataFrom = 1234560;
cout << "dataFrom = " << asctime(gmtime(&dataFrom)) << "\n";
return 0;
}
如何正确使用 gdb 打印 dataFrom?我读过关于通知 gdb 一个结构,如果它是用户定义的。但是如何处理诸如 time_t 之类的内置内容?
badri@badri-All-Series:~/progs$ g++ --std=c++11 testgdb.cpp -g
badri@badri-All-Series:~/progs$ gdb ./a.out
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) b main
Breakpoint 1 at 0x903: file testgdb.cpp, line 9.
(gdb) r
Starting program: /home/badri/progs/a.out
Breakpoint 1, main () at testgdb.cpp:9
9 {
(gdb) n
10 time_t dataFrom = 1234560;
(gdb) p dataFrom
= 93824992233952
(gdb) p *dataFrom
= 1447122753
(gdb) p/s dataFrom
= 93824992233952
是的,如 by n. 1.8e9-where's-my-share m,执行到第9行就停止了,第10行还未执行。因此,gdb 中的一个简单 next
或 n
命令将 运行 第 10 行,然后如果您打印 dataFrom
中的值,您可以观察到正确的值。
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
...
Reading symbols from ./a.out...
(gdb) b main
Breakpoint 1 at 0x11e9: file testgdb.cpp, line 9.
(gdb) r
Starting program: /home/user/path/a.out
Breakpoint 1, main () at testgdb.cpp:9
9 {
(gdb) n
10 time_t dataFrom = 1234560;
(gdb) p dataFrom
= 0
(gdb) n
11 cout << "dataFrom = " << asctime(gmtime(&dataFrom)) << "\n";
(gdb) p dataFrom
= 1234560
(gdb)
我想从 gdb 打印一些信息,但不知道如何打印。我习惯了 p/s p/x 格式。但是不知道下面的情况怎么办。
#include<iostream>
#include<climits>
#include <stdio.h>
#include <time.h>
#include <stdint.h>
using namespace std;
int main()
{
time_t dataFrom = 1234560;
cout << "dataFrom = " << asctime(gmtime(&dataFrom)) << "\n";
return 0;
}
如何正确使用 gdb 打印 dataFrom?我读过关于通知 gdb 一个结构,如果它是用户定义的。但是如何处理诸如 time_t 之类的内置内容?
badri@badri-All-Series:~/progs$ g++ --std=c++11 testgdb.cpp -g
badri@badri-All-Series:~/progs$ gdb ./a.out
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) b main
Breakpoint 1 at 0x903: file testgdb.cpp, line 9.
(gdb) r
Starting program: /home/badri/progs/a.out
Breakpoint 1, main () at testgdb.cpp:9
9 {
(gdb) n
10 time_t dataFrom = 1234560;
(gdb) p dataFrom
= 93824992233952
(gdb) p *dataFrom
= 1447122753
(gdb) p/s dataFrom
= 93824992233952
是的,如next
或 n
命令将 运行 第 10 行,然后如果您打印 dataFrom
中的值,您可以观察到正确的值。
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
...
Reading symbols from ./a.out...
(gdb) b main
Breakpoint 1 at 0x11e9: file testgdb.cpp, line 9.
(gdb) r
Starting program: /home/user/path/a.out
Breakpoint 1, main () at testgdb.cpp:9
9 {
(gdb) n
10 time_t dataFrom = 1234560;
(gdb) p dataFrom
= 0
(gdb) n
11 cout << "dataFrom = " << asctime(gmtime(&dataFrom)) << "\n";
(gdb) p dataFrom
= 1234560
(gdb)