Page MenuHomePhabricator

[LLDB] Addresses can be two bytes in size
Needs ReviewPublic

Authored by aykevl on Tue, Feb 4, 5:57 AM.

Details

Summary

Addresses are usually two bytes in size on AVR, so make sure LLDB deals with that.


I'm not sure I caught all cases. In particular, lldb/include/lldb/DataFormatters/FormattersHelpers.h might be related but I've left it alone as it didn't seem to be necessary.

Honestly I think LLDB would become a lot more forgiving to uncommon architectures when these asserts are removed and avoids assumptions based on the address size. When the address size is relevant (for example, to read a value from memory), it should have an exhaustive test with a default case that does an assert (for easy debugging). For example:

switch (addr_size) {
case 4:
    // do one thing
case 8:
    // do something else
default:
    assert(false && "unknown addr_size");
}

This way, it's easy to find the places that make these assumptions just by following the asserts.

I'm not sure how to add a test for this. I can test it locally by connecting to a remote debugger (simavr). However, I don't know how to do something like that in the LLDB testing framework. Additionally, for that to work I only needed the change in DumpDataExtractor.cpp so I'm not sure how to exhaustively test this.

Diff Detail

Event Timeline

aykevl created this revision.Tue, Feb 4, 5:57 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptTue, Feb 4, 5:57 AM
labath added a comment.Tue, Feb 4, 3:24 PM

You should be able to test most (if not all) of this stuff without an actual process. lldb can display global variables, set breakpoints, resolve addresses, etc. without being connected to a debug stub.

How do you normally generate the binaries with these kinds of addresses? Can they be produced with clang? Can they be produced with llvm-mc? Linked with lld ?

andwar added a subscriber: andwar.Wed, Feb 5, 10:54 AM

How do you normally generate the binaries with these kinds of addresses? Can they be produced with clang? Can they be produced with llvm-mc? Linked with lld ?

With avr-gcc. I think it's easiest to just generate a minimal binary using yaml2obj.

For the rest I'm focusing on D73969 now, this patch should probably be abandoned.

labath added a comment.Wed, Feb 5, 2:30 PM

How do you normally generate the binaries with these kinds of addresses? Can they be produced with clang? Can they be produced with llvm-mc? Linked with lld ?

With avr-gcc. I think it's easiest to just generate a minimal binary using yaml2obj.

For the rest I'm focusing on D73969 now, this patch should probably be abandoned.

yaml2obj can certainly be useful, the yaml files are not that readable when you need to create more complicated inputs (e.g. with DWARF). Writing assembly could be more useful there.

But anyway, we can evaluate that on a case-by-case basis.