3

I'm using a .gdbinit file that is supposed to print the values of all registers at every hook_stop, followed by the stack and data frames. However, when running many programs, there are often segment registers that are unavailable, which is causing me problems. The script aborts when it encounters such a register. I get the error message: Error while running hook_stop: value is not available. Because of the error, none of the remaining segment registers are printed, nor are the stack and data frames.

I want to know if there is a way to handle the error in the gdb scripting language, or better yet, just test if a register is available, and only print it if it is. I've tried:

if $ds
    printf " %04X  ", $ds
else
    printf " ----  "
end

but that's still giving me the error. I read through the docs for hours and couldn't find anything that worked. Any ideas?

2

I've figure it out. You can figure out if a value is available by inspecting it via python:

I've create a convenience function which you can call from your .gdbinit to easily check if the value is available.

Save this in a python file and source it in your .gdbinit:

class IsValid (gdb.Function):
    def __init__ (self):
        super (IsValid, self).__init__("isvalid")

    def invoke (self, var):
        if var.__str__() == "<unavailable>":
            return 0
        else:
            return 1

IsValid ()

By calling this convenience function, you can branch to handle the error:

if ($isvalid($ds))
    printf " %04X  ", $ds
else
    printf " ----  "
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.