Bug 21886 - Compressed MIPS code debugging impossible due to memory breakpoint misplacement
Summary: Compressed MIPS code debugging impossible due to memory breakpoint misplacement
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: HEAD
: P1 critical
Target Milestone: 8.0.1
Assignee: Maciej W. Rozycki
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-02 17:44 UTC by Maciej W. Rozycki
Modified: 2017-08-11 14:25 UTC (History)
0 users

See Also:
Host:
Target: mips*-*-*
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej W. Rozycki 2017-08-02 17:44:10 UTC
As from commit cd6c3b4ffc4e ("New gdbarch methods breakpoint_kind_from_pc 
and sw_breakpoint_from_kind") it is not possible to debug compressed MIPS
code due to the ISA bit being retained in the memory breakpoint location.
Consequently the software breakpoint instruction is patched in starting
from the second byte of the intended original instruction and therefore
corrupts code being debugged.  This usually renders debugging impossible,
e.g. with MIPS16 code and the Linux target any dynamic executable
crashes:

(gdb) continue
Continuing.

Program received signal SIGBUS, Bus error.
_dl_debug_initialize (ldbase=0, ns=0) at dl-debug.c:51
51	    r = &_r_debug;
(gdb)

See <https://sourceware.org/ml/gdb-patches/2017-08/msg00011.html> for a
proposed fix.
Comment 1 Sourceware Commits 2017-08-07 16:03:25 UTC
The master branch has been updated by Maciej W. Rozycki <macro@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ba7b109b296feac8cf8cab74db5f824dfa631610

commit ba7b109b296feac8cf8cab74db5f824dfa631610
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Mon Aug 7 17:02:04 2017 +0100

    PR breakpoints/21886: mem-break: Fix breakpoint insertion location
    
    Fix a commit cd6c3b4ffc4e ("New gdbarch methods breakpoint_kind_from_pc
    and sw_breakpoint_from_kind") regression and restore the use of
    `->placed_address' rather than `->reqstd_address' as the location for a
    memory breakpoint to be inserted at.  Previously
    `gdbarch_breakpoint_from_pc' was used that made that adjustment in
    `default_memory_insert_breakpoint' from the preinitialized value,
    however with the said commit that call is gone, so the passed
    `->placed_address' has to be used for the initialization.
    
    The regression manifests itself as the inability to debug any MIPS/Linux
    compressed ISA dynamic executable as GDB corrupts the dynamic loader
    with one of its implicit breakpoints, causing the program to crash, as
    seen for example with the `mips-linux-gnu' target, o32 ABI, MIPS16 code,
    and the gdb.base/advance.exp test case:
    
    (gdb) continue
    Continuing.
    
    Program received signal SIGBUS, Bus error.
    _dl_debug_initialize (ldbase=0, ns=0) at dl-debug.c:51
    51	    r = &_r_debug;
    (gdb) FAIL: gdb.base/advance.exp: Can't run to main
    
    	gdb/
    	PR breakpoints/21886
    	* mem-break.c (default_memory_insert_breakpoint): Use
    	`->placed_address' rather than `->reqstd_address' for the
    	breakpoint location.
Comment 2 Sourceware Commits 2017-08-11 09:50:06 UTC
The gdb-8.0-branch branch has been updated by Maciej W. Rozycki <macro@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b3e687f4c5e2bd847ea0608fd8960820f3efbda3

commit b3e687f4c5e2bd847ea0608fd8960820f3efbda3
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Fri Aug 11 10:40:06 2017 +0100

    PR breakpoints/21886: mem-break: Fix breakpoint insertion location
    
    Fix a commit cd6c3b4ffc4e ("New gdbarch methods breakpoint_kind_from_pc
    and sw_breakpoint_from_kind") regression and restore the use of
    `->placed_address' rather than `->reqstd_address' as the location for a
    memory breakpoint to be inserted at.  Previously
    `gdbarch_breakpoint_from_pc' was used that made that adjustment in
    `default_memory_insert_breakpoint' from the preinitialized value,
    however with the said commit that call is gone, so the passed
    `->placed_address' has to be used for the initialization.
    
    The regression manifests itself as the inability to debug any MIPS/Linux
    compressed ISA dynamic executable as GDB corrupts the dynamic loader
    with one of its implicit breakpoints, causing the program to crash, as
    seen for example with the `mips-linux-gnu' target, o32 ABI, MIPS16 code,
    and the gdb.base/advance.exp test case:
    
    (gdb) continue
    Continuing.
    
    Program received signal SIGBUS, Bus error.
    _dl_debug_initialize (ldbase=0, ns=0) at dl-debug.c:51
    51	    r = &_r_debug;
    (gdb) FAIL: gdb.base/advance.exp: Can't run to main
    
    	gdb/
    	PR breakpoints/21886
    	* mem-break.c (default_memory_insert_breakpoint): Use
    	`->placed_address' rather than `->reqstd_address' for the
    	breakpoint location.
    
    (cherry picked from commit ba7b109b296feac8cf8cab74db5f824dfa631610)
Comment 3 Maciej W. Rozycki 2017-08-11 14:25:38 UTC
Fixed in master and 8.0, closing bug.
Comment 4 Maciej W. Rozycki 2017-08-11 14:25:55 UTC
Fixed in master and 8.0, closing bug.