<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="">I would suggest using python here. You can make a new LLDB command in a python file and then "command script import /path/to/my/file.py". This python script would install a new command and you  can then just run that command. Happy to help you get this script working off the mailing lists if you need help.<div class=""><br class=""></div><div class="">In the python you might be able to do something a bit smarter than trying to subtract 24 from the PC. This if very error prone because opcodes for x86 vary in size and this value might be in the middle of an opcode. It might be better to get the function for the current PC and get its instructions in python:</div><div class=""><br class=""></div>>>> pc = frame.GetPCAddress()<br class="">>>> print(pc)<br class="">a.out`main + 36 [inlined] squares(int, int) at main.cpp:17<br class="">a.out`main + 36 at main.cpp:17<br class="">>>> function = pc.GetFunction()<br class="">>>> if not function.IsValid():<br class="">...   function = pc.GetSymbol()<div class="">... <br class="">>>> print(function)<br class="">SBFunction: id = 0x7fffffff00000122, name = main, type = main<br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Now "function" is either a lldb.SBFunction or lldb.SBSymbol. Both types have a "GetInstructions(...)" method which can be used to grab a lldb.SBInstructionList for all instructions in that function or symbol:</div><div class=""><br class="">>>> instructions = function.GetInstructions(target)<br class="">>>> for instruction in instructions:<br class="">...   print(instruction)<br class="">... <br class="">a.out[0x100000f10]: pushq  %rbp<br class="">a.out[0x100000f11]: movq   %rsp, %rbp<br class="">a.out[0x100000f14]: subq   $0x30, %rsp<br class="">a.out[0x100000f18]: movl   $0x0, -0x1c(%rbp)<br class="">a.out[0x100000f1f]: movl   %edi, -0x20(%rbp)<br class="">a.out[0x100000f22]: movq   %rsi, -0x28(%rbp)<br class="">a.out[0x100000f26]: movl   $0xa, -0xc(%rbp)<br class="">a.out[0x100000f2d]: movl   $0x14, -0x10(%rbp)<br class="">a.out[0x100000f34]: movl   -0xc(%rbp), %eax<br class="">a.out[0x100000f37]: movl   %eax, -0x8(%rbp)<br class="">a.out[0x100000f3a]: movl   -0x8(%rbp), %eax<br class="">a.out[0x100000f3d]: imull  -0x8(%rbp), %eax<br class="">a.out[0x100000f41]: movl   %eax, -0x14(%rbp)<br class="">a.out[0x100000f44]: movl   -0x10(%rbp), %eax<br class="">a.out[0x100000f47]: movl   %eax, -0x4(%rbp)<br class="">a.out[0x100000f4a]: movl   -0x4(%rbp), %eax<br class="">a.out[0x100000f4d]: imull  -0x4(%rbp), %eax<br class="">a.out[0x100000f51]: movl   %eax, -0x18(%rbp)<br class="">a.out[0x100000f54]: movl   -0x18(%rbp), %eax<br class="">a.out[0x100000f57]: addl   -0x14(%rbp), %eax<br class="">a.out[0x100000f5a]: movl   %eax, -0x14(%rbp)<br class="">a.out[0x100000f5d]: movl   -0x14(%rbp), %eax<br class="">a.out[0x100000f60]: movl   %eax, -0x2c(%rbp)<br class="">a.out[0x100000f63]: movl   -0x2c(%rbp), %esi<br class="">a.out[0x100000f66]: leaq   0x35(%rip), %rdi<br class="">a.out[0x100000f6d]: movb   $0x0, %al<br class="">a.out[0x100000f6f]: callq  0x100000f82<br class="">a.out[0x100000f74]: xorl   %ecx, %ecx<br class="">a.out[0x100000f76]: movl   %eax, -0x30(%rbp)<br class="">a.out[0x100000f79]: movl   %ecx, %eax<br class="">a.out[0x100000f7b]: addq   $0x30, %rsp<br class="">a.out[0x100000f7f]: popq   %rbp<br class="">a.out[0x100000f80]: retq   <br class=""><br class="">Each "instruction" is a "lldb.SBInstruction" that has a "GetAddress()" method which returns the lldb.SBAddress for that instruction. You can compare that to the PC value:</div><div class=""><br class=""></div><div class="">>>> for instruction in instructions:<br class="">...   if instruction.GetAddress() == pc:<br class="">...     print(instruction)<br class="">... <br class="">a.out[0x100000f34]: movl   -0xc(%rbp), %eax<br class=""><br class=""><div class="">So you can use this to find the index of the instruction that the PC is at within "instructions":</div><div class=""><br class=""></div>>>> for (i, instruction) in enumerate(instructions):<br class="">...   if instruction.GetAddress() == pc:<br class="">...     print(instruction)<br class="">...     break<br class="">... <br class="">a.out[0x100000f34]: movl   -0xc(%rbp), %eax<br class="">>>> print(i)<br class="">8<br class=""><br class="">Now you can backup as many instructions as you want and not fear that you will end up in the middle of an x86 instruction.</div><div class=""><br class=""></div><div class="">Greg<br class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> </div><div class=""><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 24, 2020, at 10:30 AM, Ted Woodward via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</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: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I have a very simple lldb script:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">thread select 1<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">disassemble --start-address $pc-24 --end-address $pc+24<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">When I run lldb with -o “process launch -s” and -s “dis.lldb”, I get odd output – the disassembly from “thread select 1” and from the disassemble command run together.<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">This is what I see with top-of-tree on Ubuntu 16:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">bin/lldb /bin/ls -o "process launch -s" -s dis.lldb<span class="Apple-converted-space"> </span><o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) target create "/bin/ls"<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Current executable set to '/bin/ls' (x86_64).<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) process launch -s<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Process 32258 launched: '/bin/ls' (x86_64)<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) command source -s 0 'dis.lldb'<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Executing commands in '/local/mnt/ted/tip/full/dis.lldb'.<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) thread select 1<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb) disassemble --start-address $pc-24 --end-address $pc+24<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">* thread #1, name = 'ls', stop reason = signal SIGSTOP<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    frame #0: 0x00007ffff7dd7c30 ld-2.23.so`_start<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">ld-2.23.so`_start:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">->  0x7ffff7dd7c30 <+0>: movq   %rsp, %rdi<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c33 <+3>: callq  0x7ffff7dd89b0            ; _dl_start at rtld.c:353<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">ld-2.23.so`_dl_start_user:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c38 <+0>: movq   %rax, %r12<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c3b <+3>: movl   0x225037(%rip), %eax      ; _dl_skip_args<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">ld-2.23.so`oom:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c18 <+13>: xorl   %eax, %eax<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c1a <+15>: callq  0x7ffff7de88f0            ; _dl_dprintf at dl-misc.c:275<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c1f <+20>: movl   $0x7f, %edi<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c24 <+25>: callq  0x7ffff7df24f0            ; __GI__exit at _exit.c:27<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c29:       nopl   (%rax)<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">ld-2.23.so`_start:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">->  0x7ffff7dd7c30 <+0>:  movq   %rsp, %rdi<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c33 <+3>:  callq  0x7ffff7dd89b0            ; _dl_start at rtld.c:353<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">ld-2.23.so`_dl_start_user:<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c38 <+0>:  movq   %rax, %r12<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c3b <+3>:  movl   0x225037(%rip), %eax      ; _dl_skip_args<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c41 <+9>:  popq   %rdx<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c42 <+10>: leaq   (%rsp,%rax,8), %rsp<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">    0x7ffff7dd7c46 <+14>: subl   %eax, %edx<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">(lldb)<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Note that the address goes from c3b to c18 right after ld-2.23.so`oom.<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">How can I separate the outputs of thread select and disassemble? If I stick in something like “register read pc” in between the thread select and the dis, I get the output from it before the output from the thread select and dis.<o:p class=""></o:p></div></div><span style="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; float: none; display: inline !important;" class="">_______________________________________________</span><br style="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;" class=""><span style="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; float: none; display: inline !important;" class="">lldb-dev mailing list</span><br style="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;" class=""><a href="mailto:lldb-dev@lists.llvm.org" style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">lldb-dev@lists.llvm.org</a><br style="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;" class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a></div></blockquote></div><br class=""></div></div></div></body></html>