Porting lldb to a new OS

Hi all,

I wanted to create lldb plugins for a new OS, but would like some advice.

I should be able to use the ABI and Disassembler plugins.
But not the others.

Where would you suggest I start implementing? Should I start with
ObjectFile, then DynamicLoader, then Core files, for example?
Debugging Core files with lldb is my first goal.

While implementing an ObjectFile plugin, without the others, how would
you suggest I test it?

I've tested a full debugger implementation, but testing
partially-implemented debuggers is different. :slight_smile:



Yes, start by getting LLDB to parse your object files.

I would start with the ObjectFile plug-in for your new file format and then test it by doing:

% lldb my_new_file.bar
(lldb) image dump sections my_new_file.bar
(lldb) image dump symtab my_new_file.bar

This lets LLDB see sections in your executable and also see the symbols involved.

With the sections: be sure to set the section type correctly for all sections (see lldb::SectionType).

It is also important to correctly classify all symbols in your symbol table. Symbol tables often contain redundant and useless symbols from a debugger perspective, so remove ones that aren't needed by the debugger (symbols with no names should probably be left out). With STAB entries in mach-o we often have to use two symbols for things since the mach-o symbol table doesn't contain sizes. We join these two symbols into a single symbol in the ObjectFileMachO. Also be sure to correctly classify all of your symbols.

Now you can start doing address and name queries to make sure those are working. Load an object file and do:

(lldb) image lookup --address ADDR --verbose

ADDR should be an address from your object file, Prior to running anything in a process, when you use "image lookup --address ADDR" you are looking up a "file address", or an address as each object file represents addresses. Make sure that address lookups work and resolve to symbols in your symbol table. If you have DWARF in your object file, make sure the "image lookup --address ADDR" find a function with file and line number.

Now is also a good time to start doing name queries. Try setting a breakpoint on a function that is in your object file:

(lldb) breakpoint set --name main

Make sure you get a resolved breakpoint location. This indicates that name lookups are working.

After you get your object file stuff working, you can now implement your Core file Process plug-in.