gdb prints wrong values when modifying arguments

I searched on gcc bugzilla and found this bug report : Bug 54218 – Debug info for function parameters is incorrect when compiled with -O0″ Althoug the report is about gcc 4.8 and I’m using 4.7, I tried the proposed workaround and it works ! Compiling with -fvar-tracking allows GDB to print the correct value … Read more

How to do bidirectional or reverse debugging of programs?

The latest gdb version 7.0 (released this week) supports reverse debugging on a number of platforms (eg. native i386 and x86_64 linux, VMware workstation, UndoDB, and Simics simulators from Virtutech). ftp://ftp.gnu.org/pub/gdb It works with the latest preview / pre-release of VMware workstation 7.0, which also supports reverse debugging of MSWindows guests using Visual Studio debugger. … Read more

Is it possible to set a gdb watchpoint programmatically?

Set hardware watchpoint from child process. #include <signal.h> #include <syscall.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <sys/ptrace.h> #include <sys/types.h> #include <sys/wait.h> #include <linux/user.h> enum { DR7_BREAK_ON_EXEC = 0, DR7_BREAK_ON_WRITE = 1, DR7_BREAK_ON_RW = 3, }; enum { DR7_LEN_1 = 0, DR7_LEN_2 = 1, DR7_LEN_4 = 3, }; typedef struct { char l0:1; … Read more

calling operator

The only way I found was this: call ‘operator<<(std::ostream&, myclass&)'(mycout, c) Since std::cout wasn’t visible to gdb for some reason, I had to resort to creating my own like this: std::ostream mycout(std::cout.rdbuf()); You haven’t stated any reasons for wanting to do this but won’t print yourvariable be easier? If this is an absolute must you … Read more

Recommended way to track down array out-of-bound access/write in C program

What is the recommended way to make sure that every access or write to array (allocated on stack) is actually valid (i.e. not provoking undefined behaviour) ? What if use clang on Linux with the options -fsanitize=addressand -fsanitize=undefined? It is also available in gcc: http://gcc.gnu.org/gcc-4.8/changes.html. clang with the option -fsanitize=undefined This is an example: #include … Read more

gdb Could not find operator[]

My understanding is that the compiler/linker includes only the member functions present in the source code and those are the ones I can use in gdb. Your understanding is incorrect / incomplete. std::vector is a template class. Without explicit instantiation, the compiler is required to instantiate only the methods called (usually a subset of methods … Read more