[lldb-dev] MCJIT Mach-O JIT debugging

Keno Fischer kfischer at college.harvard.edu
Mon Jun 2 08:47:45 PDT 2014

I didn't get to work on this more last week, but I'll look at incorporating
that suggestion.

The other question of course is how to do this in LLDB. Right, now what I'm
doing is going through and adjusting the load address of every leaf in the
section tree. That basically works and gets me backtraces with the correct
function names and the ability to set breakpoints at functions in JITed
modules. What it doesn't get me yet is line numbers. I suspect that is
because the DWARF still refer to the old addresses. I thought relocations
should take care of that, but apparently they don't so I'll have to look at
whether to solve this in LLDB or in LLVM. Suggestions are most welcome.

On Wed, May 28, 2014 at 12:53 PM, Greg Clayton <gclayton at apple.com> wrote:

> > On May 28, 2014, at 8:57 AM, Keno Fischer <kfischer at college.harvard.edu>
> wrote:
> >
> > Hello,
> >
> > I'm finally getting back to getting JIT debugging work for MCJIT. This
> has worked for ELF for a while in LLVM and support in lldb was added in
> January (for ELF). I'm now trying to add support for Mach-O and would
> appreciate some feedback (though I'm fighting my way through learning the
> format, I'm still just a novice).
> >
> > My current patchset for llvm is here:
> https://gist.github.com/loladiro/8d909ddd04e6d7e9a5d0 . I have a
> corresponding patch for lldb and I basically got this working (modulo line
> table information, though I'm sure I'm doing something stupid in lldb here).
> > The basic approach is to, when a section gets allocated rewrite the
> sections `addr` and update every symbols `n_value` correspondingly. This is
> very much in line with what is done for ELF, but I'm not sure if it's the
> right approach, so I'd appreciate if somebody who has more experience with
> Mach-O could look at the above patch and give some feedback. If this
> approach looks sane in general, I'll finish up and post both the LLVM and
> the LLDB patch for formal review.
> The one thing you might want to look into is the n_value only needs to be
> updated "if ((N_TYPE & n_type) == N_SECT)" (the symbol is in a section and
> therefore is has a address value). Other symbols have values that usually
> don't need to be modified. You might also need to watch out for absolute
> symbols (if ((N_TYPE & n_type) == N_ABS)) as there are a few that sometimes
> don't claim to be a symbol that has a valid address, but they actually do
> point to an address. The symbol named "mach_header" is one such absolute
> symbol.
> If this is all new code, get it as close as you can and then we can work
> the kinks out once it is in the codebase.
> Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140602/248746a8/attachment.html>

More information about the lldb-dev mailing list