Page MenuHomePhabricator

Provide a substitute to load command of gdb
ClosedPublic

Authored by abidh on Jan 17 2017, 6:24 AM.

Details

Reviewers
clayborg
Summary

For bare-metal targets, lldb was missing a command like 'load' in gdb which can be used to create executable image on the target. This was discussed in
http://lists.llvm.org/pipermail/lldb-dev/2016-December/011752.html

This diff adds an option to "target module load" command to provide that functionality. Instead of delegating the responsibility of writing bits to memory to Module or Objfile as was discussed in the thread above, it seemed simple to do it right in the command. Otherwise it looks straight forward. I have added a little code so that this option can be used with specifying the file so that it is easy to alias this long command to something simple. I was not sure what should be the name of that option. So I am open to suggestion.

Tested with qemu and STM32L476 board and works ok. Although it needs a few more changes else where in lldb to make them work. Those changes will come in separate commits.

Diff Detail

Event Timeline

abidh created this revision.Jan 17 2017, 6:24 AM
clayborg requested changes to this revision.Jan 17 2017, 9:23 AM

We need to agree on options names and move the object file loading code into ObjectFile.cpp. See inlined comments.

source/Commands/CommandObjectTarget.cpp
2570

How about "--load" witg -l as a short option? "--write-to-mem" seems a bit long.

2571–2572

I am guessing we will have other clients that will want to load more than one image to memory so I am not sure bundling setting the PC should always happen. This might be better as another option: "--set-pc-to-entry" or -p? Then you could load the main image and any other images needed. I know EFI does something similar to this.

2591–2631

We should have a Module and ObjectFile method to do this. Move this code there in a function like:

lldb_private::Error lldb_private::Module::LoadInMemory(Target &target);

This will call through to the ObjectFile method:

lldb_private::Error lldb_private::ObjectFile::LoadInMemory(Target &target);

We should have each object file subclass override this method as well. When loading and ELF file you load only the program headers into memory as directed by the contents of the file. With mach-o you would load the entire file into memory with the exception of some of the __LINKEDIT section, but again this depends on the contents of the file. So each object file subclass should do this as they see fit. We could have a default implementation do this in ObjectFile.cpp that does what you did above: load the section contents only depending on the section load lists for that module/object file. Then we would let ObjectFileMachO override this method if we ever need to.

This revision now requires changes to proceed.Jan 17 2017, 9:23 AM
abidh updated this revision to Diff 84979.Jan 19 2017, 9:12 AM
abidh edited edge metadata.

Changed the name of the option. Added LoadInMemory function to Module and ObjectFile class and moved the functionality of writing to memory there. Removed part which set the pc.

clayborg accepted this revision.Jan 19 2017, 9:14 AM

Very nice!

This revision is now accepted and ready to land.Jan 19 2017, 9:14 AM
abidh closed this revision.Jan 19 2017, 9:46 AM

Committed in 292499. Removed this bit "set PC to its entry address." before committing as it is not being done now.