All notes

Breakpoints Another reference from Mac LLDB.

break test.c:1	# Set breaks
info break [n]	# Print break pionts.
delete 1	# Delete the first breakpoint.
watch gvar	# Set a watchpoint on a variable when it is written to.

# Save all current breakpoints to a file.
save breakpoints filename
# Read the saved breakpoint definitions.
source filename

# list current line.
list *$pc

info args/locals	# Show the arguments and local variables for the current frame.
info registers
info types REGEXP
# Show information about the current source file:
info source
# Print the names of all source files in your program:
info sources
# Print the names and data types of all defined functions:
info functions
info functions REGEXP

# Look up information for a type Point by name, in detail.
ptype Point
# Just print the type info.
whatis Point
# looks up the value of `x' in the scope of the file `foo.c'.
p 'foo.c'::x
set case-sensitive on/off/auto
show case-sensitive

# SourceWare.
p var	# Print variable content.
p/x var	# Print var in hex format.
p/t var	# Print var in binary format. ‘t’ stands for “two”.
p/d # Print as integer in signed decimal.
p/u # Print as integer in unsigned decimal.
p/o # Print as integer in octal.
p/c # Print as char.
p/f # Print as float.
p/s var # Print as string.
p/r # Print as raw.
display var	# Display the var every time you stop.

# x, examing memory.
# SourceWare.
x addr

set $foo = 5
set env DEBUG 1 # Set environment variables for process before launching.

finish	# Step out current frame.
step	# Do a source-level step in the currently selected thread.
next	# Do a source-level step over in the currently selected thread.
stepi	# Do an instruction-level step in currently selected thread.
nexti	# Do an instruction-level step over in currently selected thread.

# Evaluate expression, which may include functions.
print EXPR
call EXPR
# You can cancel execution of a function call with the value "EXPRESSION" returned.
# Give a signal. SIGNAL could be, for example, SIGINT.
signal SIGNAL

bt	# Show backtrack.
bt 5	# Backtrace the first five frames of the current thread.
up/down	# Select the upper/lower stack frame from the current frame.

# Save binary memory data to a file starting at 0x1000 and ending at 0x2000.
dump memory /tmp/mem.bin 0x1000 0x2000

# Attach GDB to a process
attach pid

gdb --args executablename arg1 arg2 arg3

gdb exeName coreFile

Core dump


# In BASH:
ulimit -c unlimited

# In tcsh
limit coredumpsize unlimited

"The reason why core dumps are not generated by default is that the limit is not set and/or set to 0, which prevents the core from being dumped. By setting a limit of unlimited, we guarantee that core dumps can always be generated."

Cent OS


/proc/sys/kernel/core_pattern is used to specify a core dumpfile pattern name.

If the first character of the pattern is a '|', the kernel will treat the rest of the pattern as a command to run. The core dump will be written to the standard input of that program instead of to a file.


GDB find no symbol


The culprit turned out to be a mismatch between the compiler and debugger! I had recently switched to GCC 4.8, a newer version. However, I was still using the old version of GDB. In v4.8, GCC produces debugging information in the DWARF4 format, as explained in its release notes. However, this older version of GDB could only understand DWARF3 or versions older than that. It was failing silently when local variables were requested.

The solution was simple: request GCC to produce debugging information in the older format by specifying -gdwarf-3. Once I did this, GDB could print local variables and they appeared in Eclipse CDT too.

GNU. As noted in the release notes for GCC 4.8 (i.e. current trunk):

DWARF4 is now the default when generating DWARF debug information. When -g is used on a platform that uses DWARF debugging information, GCC will now default to -gdwarf-4 -fno-debug-types-section. GDB 7.5, Valgrind 3.8.0 and elfutils 0.154 debug information consumers support DWARF4 by default. Before GCC 4.8 the default version used was DWARF2. To make GCC 4.8 generate an older DWARF version use -g together with -gdwarf-2 or -gdwarf-3. The default for Darwin and VxWorks is still -gdwarf-2 -gstrict-dwarf.