I want to understand an error that occurs in a program. This program uses the GLib class DateTime. I want to understand what is happening there. Therefore I want to build a sample program that uses the same function calls.
#include <glib.h>
#include <glibmm.h>
#include <stdio.h>
int main()
{
Glib::DateTime start_time;
long int tv_sec = start_time.to_unix();
long int tv_usec = start_time.get_microsecond();
printf("%ld %ld\n", tv_sec, tv_usec);
}
Using the Compiling GLib Applications manual I found this as the required compile command:
$ g++ `pkg-config --cflags glibmm-2.4` main.cpp `pkg-config --libs glibmm-2.4`
The compiled ./a.out issues an error message:
Segmentation fault (core dumped)
I can't find anything at /var/crash and I even don't know how to evaluate the core dump. Therefore I add debug info and run this in GDB:
$ g++ -g `pkg-config --cflags glibmm-2.4` main.cpp `pkg-config --libs glibmm-2.4`
$ gdb ./a.out
(gdb) break main
(gdb) run
Breakpoint 1, main () at main.cpp:6
6 {
(gdb) next 2
9 tv.tv_sec = start_time.to_unix();
(gdb) next
Program received signal SIGSEGV,Segmentation fault.
0x00007ffff6881854 in g_date_time_to_unix () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
(gdb) disas
0x#### push %rbx
0x#### mov %rdi,%rbx
==> 0x#### mov 0x10(%rdi),%esi
....
(gdb) info reg rbx rdi
rbx 0x0 0
rdi 0x0 0
(gdb) where
#0 0x#### in g_date_time_to_unix () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#1 0x#### in main() () at main.cpp:9
(Some addresses are abbreviated.)
Somehow this simple program fails. I can't imaging that this can be a bug in a library that is used in the field.
- How can I find what's going wrong?
- Did I used the DateTime class incorrectly?