Sanketh Gowda S
Sanketh Gowda S

Reputation: 1

How to read the structure values in gdb?

For example, when I type

p dest-msgs[count]

The following values are displayed. How to understand the significance of these values ?

p dest->msgs[count]
$9 = {hdr = {ver = 5 '\005', magic = 18 '\022', evt_len = 588}, evt = {hdr = {ver = 3 '\003', magic = 18 '\022', evt_len = 552}, service_id = 1, instance = 0, comp_id = -2136604671, 
    comp_name = "tsd", '\0' <repeats 14 times>, flags = 0, objid = 0, file = "ts.c", '\0' <repeats 11 times>, func = "tsTimeMcast_h\000\000", line = 1667, local_time_sec = 1483252020, 
    local_time_usec = 28575, time_sec = 1483252020, time_usec = 28675, global_seq = 4014, external_seq = 2146, iq_drop = 0, rq_drop = 0, 
    arg_offset = "\000\002\005\006", '\0' <repeats 11 times>, arg = "LOCL\000\000\000\000External\000\000\000\000EXT\000LOCL", '\0' <repeats 227 times>, msgdef = {msg_id = 0, 
      attributes = 0, class = 0, severity = 0, msg_value = "\000\000\000\000\000\000\000\000\000", message = '\0' <repeats 128 times>, arg_type = 0, arg_num = 0, 
      cat_name = "\000\000\000\000\000\000\000"}}, name = '\0' <repeats 31 times>}

Upvotes: 0

Views: 145

Answers (1)

j6t
j6t

Reputation: 13387

Let's see what we have here:

p dest->msgs[count]

So, you print one particular element from an array, it seems. Gdb responds:

$9 = {

This $9 is just an artificial name that you could use later to refer to this result. The result begins with an opening brace. This means that it is a structure. It goes on:

hdr = {ver = 5 '\005', magic = 18 '\022', evt_len = 588},

The first member of the structure has the name hdr and its value is, see the next opening brace, again a structure. This nested structure has three members (the closing brace tells us where we have to stop counting) named ver, magic, and evt_len. You see their respective values. Then follows

evt = {hdr = {ver = ...

that is, evt is the second member of the outer structure, which is again a structure, which has member hdr, which is again a structure. Et cetera.

Upvotes: 1

Related Questions