Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get a nice output for the flags register using lldb?

Here is the output I get when I read the rflags register using lldb

(lldb) register read rflags
  rflags = 0x0000000000000246

I know each bit represents a certain flag, but it would be nice to have an output that gave me the value of those flags (e.g. carry flag, zero flag, etc...)

Is there any way to do that using lldb?

like image 840
MathStudent Avatar asked Dec 06 '17 20:12

MathStudent


1 Answers

There isn't an automatic way to do this.

You can't use the data formatters since they are linked to types and there isn't a "flags register type". And the formats you can pass on the command line to register read format the whole value.

We've toyed with the idea of adding "register formatters" along the same lines as the data formatters, but haven't implemented that yet.

You could pretty easily write an lldb command to pretty-print the value however. If you start from the example here:

http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/cmdtemplate.py

you can see the example gets the frame here:

frame = exe_ctx.GetFrame()

You could then get the register value from:

rflags_value = frame.FindRegister("rflags")

You can either get the value as a whole

error = lldb.SBError()
uint_value = rflags_value.GetValueAsUnsigned(error)

But it might be easier for your purposes to get the SBData for this:

data_value = rflags_value.GetData()

The SBData object lets you see the value as a vector of uint8's. It doesn't produce smaller chunks, but still this might help:

first_byte = data_value.uint8[0]

etc. When you have formatted this as you wish, write the description into the return object you were passed, and that's what the command will return. The __init section shows how to make this into an lldb command. Then just put:

command script import <path_to_py>/my_command.py

and it will be available in all your future lldb sessions.

Here's more documentation on the lldb API's:

http://lldb.llvm.org/python_reference/index.html

and you can use the python "script interpreter" REPL in lldb (the script command) to play with these API's as you are developing the code.

like image 73
Jim Ingham Avatar answered Oct 15 '22 01:10

Jim Ingham