This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

embedded_offset missing in c-valprint.c


Hi,

Could you please consider the attached patch to c-valprint.c ?

Unless I am mistaken (which is possible), the function c_val_print does
not correctly track the inferior addresses of struct members. This
affects pretty-printing via python scripting, which may require this
address.

I actually tested the version from the ubuntu package 7.1-1ubuntu2, but
the defect seems also present in the git head version.

Here is an example of a session transcript illustrating the misbehaviour/

$ gdb v
GNU gdb (GDB) 7.1-ubuntu
[...]
(gdb) b 19
Breakpoint 1 at 0x4004fb: file v.c, line 19.
(gdb) r
Starting program: /home/thome/Curves/CM/complex_analytic/regis/v 

Breakpoint 1, main () at v.c:19
19          return 0;
(gdb) p x
$1 = {{l = 42, a = {{{x = 0}}, {{x = 1}}}}}
(gdb) source u.py
(gdb) p x
$2 = {{l = 42, a = {42, 0}}}

v.c and u.py are attached (as well as the patch itself of course).

Best,

E.
struct bar {
    int x;
};

typedef struct bar xbar[1];

struct foo {
    int l;
    xbar a[2];
};

int main()
{
    struct foo x[1];
    x->l = 42;
    for(int i = 0 ; i < 2 ; i++)
        x->a[i]->x=i;
    return 0;
}
import gdb
from gmpy import mpz,mpf

class bar_printer:
    def __init__(self, val):
        self.val = val
    def to_string(self):
        X = self.val
        # There's apparently a bug in array member of structs. Their
        # starting address seems to be constantly equal to the starting
        # address of the struct itself...
        return str(int(X['x']))


def make_my_printer_objects(val):
    t=str(val.type)
    if t == 'struct bar [1]':
        return bar_printer(val[0])
    return None

gdb.pretty_printers.append(make_my_printer_objects)

Attachment: p
Description: c-valprint-patch


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]