GDB now has a running copy of ogg123
stopped at the very start of flac_read
. Pretty jazzy huh? You can see the values of the arguments in the second-to-last line it printed, so for example you can see that the caller has requested to read 30240 bytes of data. The various structures (decoder=0x637560
etc) aren’t so useful as they’re pointers, but we can deference them with the print
command:
(gdb) print *decoder
$1 = {source = 0x637060, request_fmt = {big_endian = 0, word_size = 2,
signed_sample = 1, rate = 0, channels = 0, matrix = 0x0}, actual_fmt = {
big_endian = 0, word_size = 2, signed_sample = 1, rate = 0, channels = 0,
matrix = 0x0}, format = 0x617ec0, callbacks = 0x7fffffffe3a0,
callback_arg = 0x0, private = 0x6375d0}
That’s pretty nice, we can see for example what format it wants the data in: little endian, signed, etc. Also, notice the line of code it stopped on:
253 flac_private_t *priv = decoder->private;
That’s the next line of code GDB will execute if we set the program going again in some way. We can advance over just that line with the next
command:
(gdb) next
254 decoder_callbacks_t *cb = decoder->callbacks;
Now it’s initialised the local variable priv
, which we can also print out:
(gdb) p *priv
$2 = {decoder = 0x637000, is_oggflac = 0, channels = 2, rate = 44100,
bits_per_sample = 16, totalsamples = 13337016, currentsample = 0,
samples_decoded = 4096, samples_decoded_previous = 0, bytes_read = 24576,
bytes_read_previous = 0, comments = 0x638240, bos = 1, eos = 0,
buf = 0x637020, buf_len = 4096, buf_start = 0, buf_fill = 4096, stats = {
total_time = 0, current_time = 0, instant_bitrate = 0, avg_bitrate = 0}}
Did you see what I did there? Most GDB commands have abbreviated forms, and the abbreviation for print
is p
. The commands I’ve introduced in this article are some of the most commonly used, and their abbreviated forms are all simply their first letter: b
for breakpoint
, r
for run
and n
for next
. You can also repeat the previous command by pressing Return, which is handy for doing a load of next
commands one after the other, for instance.