vendredi 8 octobre 2021

Using gdb to print a time_t variable

I want to print some information from gdb but don't see how. I am used to p/s p/x formats. But don't know what to do in the case below.

#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;
}

How do i print dataFrom using gdb correctly ? I have read about informing gdb about a structure if it was user defined. But what to do with something inbuilt such as 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
$1 = 93824992233952
(gdb) p *dataFrom
$2 = 1447122753
(gdb) p/s dataFrom
$3 = 93824992233952

Aucun commentaire:

Enregistrer un commentaire