vuvova / gdb-tools

Various tools to improve the gdb experience
BSD 3-Clause "New" or "Revised" License
123 stars 17 forks source link

Add printer format (like /x) in DUEL #8

Open jreybert opened 6 years ago

jreybert commented 6 years ago

IMO, there is a fundamental printing behavior missing here, the support of print format:

FMT is a repeat count followed by a format letter and a size letter. Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address), i(instruction), c(char), s(string) and z(hex, zero padded on the left). Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes). The specified number of objects of the specified size are printed according to the format.

Anyway, I can't wait the next bug to really test DUEL, thanks!

vuvova commented 6 years ago

I'm not quite sure how to fit it into the language. In duel one can easily print many values of different types, like

(gdb) dl 1,2.0,"foo"

or, more practical

(gdb) dl root-->next->(id, name)

So, may be something like

(gdb) dl root-->next->(id //x , name //s)

But if it's an operator, then it's not very clear what its precedence and how it applies to expressions, for example:

(gdb) dl root-->next->(id , name) //x

or even

(gdb) dl root-->next//x->(id , name)
jreybert commented 4 years ago

Any news about this enhancement?

Today, gdb does not care about the granularity of /x operator: it's all members.

At least, such simple granularity is at least necessary in my point of view: I can't easily use dl to review a bunch of pointers. If you are able to define and implement a per-memeber operator, it would be a real plus.

Can I help you in something? If you don't have time to implement this, I can try to do a PR, but I have to dive into your the source code, and I certainly will need your support.

vuvova commented 4 years ago

Thanks. It's not a question of time, it, probably, wouldn't need much time to implement.

It's just that I don't understand how to fit the concept of these /x formats into duel.

Simple dl/x can be implemented quickly, though. /x is parsed in the invoke method in __init__.py and it should set some kind of a flag that val2str will use to print pointers as you like it.

jreybert commented 4 years ago

I tried to dive into your parser, but I start from too far, and I don't really understand where I from where to start. Any hint on how to add a new parser entry?

vuvova commented 4 years ago

There is no need to modify the parser as such. I'd do something like

  if arg.startswith("/x"):
    hex_mode=True
    arg=arg[2:]