[llvm-bugs] [Bug 50948] New: LLDB not clearing EXC_BAD_ACCESS exception after `thread return` (on MacOS)?

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 30 10:30:26 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50948

            Bug ID: 50948
           Summary: LLDB not clearing EXC_BAD_ACCESS exception after
                    `thread return` (on MacOS)?
           Product: lldb
           Version: unspecified
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: lldb-dev at lists.llvm.org
          Reporter: vyng at google.com
                CC: jdevlieghere at apple.com, llvm-bugs at lists.llvm.org

Repro:

Using the following test code:

// bad_access.cc
     1  // bad_access.cc
     2  #include <stdio.h>
     3  #include <stdlib.h>
     4  
     5  int bad_acc(void){
     6    printf("in bad_acc()\n");
     7    
     8    // cause bad mem access here
     9    return *(int*)(123);
    10  }
    11  
    12  int main () {
    13    printf( "hello world\n");
    14    // bad access here
    15    bad_acc();
    16    printf("bye world\n");
    17    return 0;
    18  }
vyng-macbookpro2% 
// Compile and run with lldb:

% clang -g -o bad_acc bad_access.cc
% lldb
(lldb) target create "bad_acc"
Current executable set to '<path_to>/bad_acc' (x86_64).
(lldb) 
Current executable set to '<path_to>/bad_acc' (x86_64).
(lldb) run
Process 97548 launched: '<path_to>/bad_acc' (x86_64)
hello world
in bad_acc()
Process 97548 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=1, address=0x7b)
    frame #0: 0x0000000100003f0b bad_acc`bad_acc() at bad_access.cc:9:10
   6      printf("in bad_acc()\n");
   7      
   8      // cause bad mem access here
-> 9      return *(int*)(123);
   10   }
   11   
   12   int main () {
Target 1: (bad_acc) stopped.
(lldb) thread return
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=1, address=0x7b)
    frame #0: 0x0000000100003f45 bad_acc`main at bad_access.cc:16:3
   13     printf( "hello world\n");
   14     // bad access here
   15     bad_acc();
-> 16     printf("bye world\n");
   17     return 0;
   18   }
(lldb) register write pc `$pc-8`
(lldb) register write pc `$pc-8`
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=1, address=0x7b)
  * frame #0: 0x0000000100003f35 bad_acc`main at bad_access.cc:13:3
    frame #1: 0x00007fff204e8f5d libdyld.dylib`start + 1
    frame #2: 0x00007fff204e8f5d libdyld.dylib`start + 1
(lldb) n
Process 97548 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=1, address=0x27e80d)
    frame #0: 0x0000000100003f35 bad_acc`main at bad_access.cc:13:3
   10   }
   11   
   12   int main () {
-> 13     printf( "hello world\n");
   14     // bad access here
   15     bad_acc();
   16     printf("bye world\n");
Target 1: (bad_acc) stopped.


------------------------------------------

Details:

After the processed stopped on bad_access.cc:9, I used `thread return` and two
`register write pc `$pc-8`` hoping to get back to bad_access.cc:13 to restart
the exececution.

- Expected behaviour: the exception is cleared and the program restarted.
- What actually happened: exception didn't clear and the program failed to
continue. (Even though `bt` showed that we were now back to line 13).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210630/758c6432/attachment.html>


More information about the llvm-bugs mailing list