<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Sounds like you got close. <div class=""><br class=""></div><div class="">What does your target look like when you type:</div><div class=""><br class=""></div><div class="">(lldb) target list</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I forgot to mention one thing that we do for ELF files:<div class=""><br class=""></div><div class="">We make sections named PT_LOAD[N] where in N starts at zero. We do this because this is essentially how dynamic loaders actually load the binary in an OS, so it makes it easier for us. All sections from the section headers that are contained within a program header, will be made children of the PT_LOAD section they belong to. It is also interesting to note that any sections that are not part of a program header, like say DWARF sections, will be left as top level sections. You can easily see how the sections are organized by doing:</div><div class=""><br class=""></div><div class="">(lldb) image dump sections test.elf</div><div class=""><br class=""></div><div class="">Or you can use the python interface to see this more clearly. In the example below I use the "lldb.target" global variable to get to the target and use special python properties to be able to iterate. Also, the modules list within a target has the list of executables where the first entry (lldb.target.modules[0]) is the main executable.</div><div class=""><br class=""></div><div class="">(lldb) script<br class="">>>> for section in lldb.target.modules[0].sections:<br class="">... print(section)<br class="">... <br class="">[0x0000000000000000-0x000000000000ffd0) libfoo.so.PT_LOAD[0]<br class="">[0x0000000000010000-0x00000000000101cc) libfoo.so.PT_LOAD[1]<br class="">[0x0000000000011000-0x0000000000011004) libfoo.so.PT_LOAD[2]<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..comment<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..ARM.attributes<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_str<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_loc<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_abbrev<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_info<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_ranges<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_macinfo<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_frame<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..debug_line<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..symtab<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..shstrtab<br class="">[0x0000000000000000-0x0000000000000000) libfoo.so..strtab<br class=""><br class=""></div><div class="">And you can iterate over the subsections within PT_LOAD[0] with python as well:</div><div class=""><br class=""></div><div class="">>>> for section in lldb.target.modules[0].sections[0]:<br class="">... print(section)<br class="">... <br class="">[0x0000000000000154-0x00000000000001ec) libfoo.so.PT_LOAD[0]..note.android.ident<br class="">[0x00000000000001ec-0x0000000000000210) libfoo.so.PT_LOAD[0]..note.gnu.build-id<br class="">[0x0000000000000210-0x0000000000000750) libfoo.so.PT_LOAD[0]..dynsym<br class="">[0x0000000000000750-0x00000000000007f8) libfoo.so.PT_LOAD[0]..gnu.version<br class="">[0x00000000000007f8-0x0000000000000838) libfoo.so.PT_LOAD[0]..gnu.version_r<br class="">[0x0000000000000838-0x00000000000009c4) libfoo.so.PT_LOAD[0]..gnu.hash<br class="">[0x00000000000009c4-0x0000000000000c6c) libfoo.so.PT_LOAD[0]..hash<br class="">[0x0000000000000c6c-0x00000000000011d0) libfoo.so.PT_LOAD[0]..dynstr<br class="">[0x00000000000011d0-0x00000000000012a8) libfoo.so.PT_LOAD[0]..rel.dyn<br class="">[0x00000000000012a8-0x0000000000001980) libfoo.so.PT_LOAD[0]..ARM.exidx<br class="">[0x0000000000001980-0x0000000000001a70) libfoo.so.PT_LOAD[0]..rel.plt<br class="">[0x0000000000001a70-0x0000000000001ad0) libfoo.so.PT_LOAD[0]..ARM.extab<br class="">[0x0000000000001ad0-0x0000000000003cb4) libfoo.so.PT_LOAD[0]..rodata<br class="">[0x0000000000003cb8-0x000000000000fdc4) libfoo.so.PT_LOAD[0]..text<br class="">[0x000000000000fdd0-0x000000000000ffd0) libfoo.so.PT_LOAD[0]..plt<br class=""><br class=""></div><div class="">We put a '.' character between parent sections and their child sections, so this makes things look a bit messy in the output ("libfoo.so" + "." + "PT_LOAD[0]" + "." + ".text").</div><div class=""><br class=""></div><div class="">So try doing this:</div><div class=""><br class=""></div><div class="">(lldb) target modules load –file test.elf –load –set-pc-to-entry PT_LOAD[0] <addr> PT_LOAD[1] <addr> ...</div><div class=""><br class=""></div><div class="">Specify the address for each PT_LOAD program header and let us know if this works?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Greg<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 23, 2020, at 12:16 PM, <<a href="mailto:lulle2007200@gmail.com" class="">lulle2007200@gmail.com</a>> <<a href="mailto:lulle2007200@gmail.com" class="">lulle2007200@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">Hello,<br class="">i tried to do it like you described:<br class="">Create target with<span class="Apple-converted-space"> </span><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">‘</span><span lang="EN-GB" class="">target create --arch armv7-none-none test.elf’</span><span lang="EN-GB" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">Connect to OpenOCD with<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="">‘gdb-remote localhost:3333‘<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">(In the original message, I didn’t mention explicitly that I was connecting to OpenOCD, sorry for that)<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">Tried to load the executable to the STM32 with<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">‘target modules load –file test.elf –load –set-pc-to-entry’<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">This failed with ‘error: one or more section name + load address pair must be specified’<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">I tried again, but this time specified a section and an address.<br class="">It didn’t fail, but didn’t load the specified section to the STM32 either.<br class=""><br class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">“</span><span lang="EN-GB" class="">Is this a baseboard situation where you have an ELF file that has program headers with all of the correct load addresses?”<br class="">Yes, I have an ELF file with multiple LOAD program headers.<br class="">The entry point address and program header addresses are all set correctly.<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class=""><o:p class=""> </o:p></span></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">Von:</b><span class="Apple-converted-space"> </span>Greg Clayton <<a href="mailto:clayborg@gmail.com" class="">clayborg@gmail.com</a>><span class="Apple-converted-space"> </span><br class=""><b class="">Gesendet:</b><span class="Apple-converted-space"> </span>Donnerstag, 23. Juli 2020 01:05<br class=""><b class="">An:</b><span class="Apple-converted-space"> </span><a href="mailto:lulle2007200@gmail.com" class="">lulle2007200@gmail.com</a><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>lldb-dev@lists.llvm.org<br class=""><b class="">Betreff:</b><span class="Apple-converted-space"> </span>Re: [lldb-dev] Remote debug arm bare metal target with lldb - load executable to target<o:p class=""></o:p></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">The --load option should work if all of the program headers have the right addresses. LLDB should try to load all PT_LOAD program headers into memory at the address that they are loaded at.<o:p class=""></o:p></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Is this a baseboard situation where you have an ELF file that has program headers with all of the correct load addresses? If so, you want to make sure that you specify no OS and no vendor when loading your target:<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) target create --arch armv7-none-none<br class=""><br class="">Why? Because when LLDB knows where is no OS and no vendor then it will select the right dynamic loader plug-in. This plug-in will automatically set the "load" address for all program headers to match the "file" address found in the ELF file. If LLDB believes you have an OS that you are running on, it will try and load a dynamic loader plugin that will wait until that plugin detects that your executable has been dynamically loaded and try to set the "load" address intelligently.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">LLDB has the notion of "load" and "file" addresses. "file" addresses are addresses as they are found in each executable or shared library object file (ELF, mach-o, COFF, etc) that exists in your target. Once your program is running, the dynamic loader will try and determine the "load" address for each section within each executable using the dynamic loader plug-in. Dynamic loader plug-ins are loaded based off of the target triple in your target.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">If your ELF file has the entry point correctly set, you can use the "--set-pc-to-entry" option.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">So if you have a static ELF file where all addresses are correct, you can probably use:<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 11pt; font-family: Calibri, sans-serif;">(lldb) target create --arch armv7-none-none a.out<br class="">(lldb) target modules load --file a.out --load --set-pc-to-entry<o:p class=""></o:p></p></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">You can also set your load addresses manually using this command by specifying the any number of section name + section address tuples:<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) target create --arch armv7-none-none a.out<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) target modules load --file a.out --load --set-pc-to-entry .text 0x200000 .data 0x300000<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class="" type="cite"><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On Jul 22, 2020, at 9:10 AM, via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" style="color: blue; text-decoration: underline;" class="">lldb-dev@lists.llvm.org</a>> wrote:<o:p class=""></o:p></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hello,<o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" class="">we are trying to debug firmware running on a stm32 using OpenOCD and LLDB.<br class="">GNU-GDB provides a ‘load’ command to load the sections from an ELF file to the target device.<br class="">We have tried to use ‘target modules load --load’ command to load ELF sections to a specific address, but that didn’t work.<br class="">If there is a way at all, what is the proper way to load the executable to the target device with LLDB?</span><o:p class=""></o:p></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9pt; font-family: Menlo-Regular, serif;" class="">_______________________________________________<br class="">lldb-dev mailing list<br class=""></span><a href="mailto:lldb-dev@lists.llvm.org" style="color: blue; text-decoration: underline;" class=""><span style="font-size: 9pt; font-family: Menlo-Regular, serif;" class="">lldb-dev@lists.llvm.org</span></a><span style="font-size: 9pt; font-family: Menlo-Regular, serif;" class=""><br class=""></span><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" style="color: blue; text-decoration: underline;" class=""><span style="font-size: 9pt; font-family: Menlo-Regular, serif;" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</span></a></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></div></div></body></html>