@@ -63,18 +63,24 @@ private LinuxAMD64CFrame(LinuxDebugger dbg, Address cfa, Address rip, DwarfParse
6363 }
6464
6565 private LinuxAMD64CFrame (LinuxDebugger dbg , Address cfa , Address rip , DwarfParser dwarf , boolean finalFrame ) {
66+ this (dbg , cfa , rip , dwarf , finalFrame , false );
67+ }
68+
69+ private LinuxAMD64CFrame (LinuxDebugger dbg , Address cfa , Address rip , DwarfParser dwarf , boolean finalFrame , boolean use1ByteBeforeToLookup ) {
6670 super (dbg .getCDebugger ());
6771 this .cfa = cfa ;
6872 this .rip = rip ;
6973 this .dbg = dbg ;
7074 this .dwarf = dwarf ;
7175 this .finalFrame = finalFrame ;
76+ this .use1ByteBeforeToLookup = use1ByteBeforeToLookup ;
7277 }
7378
7479 // override base class impl to avoid ELF parsing
7580 public ClosestSymbol closestSymbolToPC () {
81+ Address symAddr = use1ByteBeforeToLookup ? pc ().addOffsetTo (-1 ) : pc ();
7682 // try native lookup in debugger.
77- return dbg .lookup (dbg .getAddressValue (pc () ));
83+ return dbg .lookup (dbg .getAddressValue (symAddr ));
7884 }
7985
8086 public Address pc () {
@@ -145,19 +151,16 @@ public CFrame sender(ThreadProxy thread) {
145151 }
146152
147153 DwarfParser nextDwarf = null ;
148- Address libptr = dbg .findLibPtrByAddress (nextPC );
149- if (libptr != null ) {
150- try {
151- nextDwarf = new DwarfParser (libptr );
152- } catch (DebuggerException e ) {
153- // Bail out to Java frame
154- }
155- }
156-
157- if (nextDwarf != null ) {
154+ boolean fallback = false ;
155+ try {
156+ nextDwarf = createDwarfParser (nextPC );
157+ } catch (DebuggerException _) {
158+ // Try again with RIP-1 in case RIP is just outside function bounds,
159+ // due to function ending with a `call` instruction.
158160 try {
159- nextDwarf .processDwarf (nextPC );
160- } catch (DebuggerException e ) {
161+ nextDwarf = createDwarfParser (nextPC .addOffsetTo (-1 ));
162+ fallback = true ;
163+ } catch (DebuggerException _) {
161164 // DWARF processing should succeed when the frame is native
162165 // but it might fail if Common Information Entry (CIE) has language
163166 // personality routine and/or Language Specific Data Area (LSDA).
@@ -166,15 +169,34 @@ public CFrame sender(ThreadProxy thread) {
166169 }
167170
168171 Address nextCFA = getNextCFA (nextDwarf , context );
169- return isValidFrame (nextCFA , context ) ? new LinuxAMD64CFrame (dbg , nextCFA , nextPC , nextDwarf )
172+ return isValidFrame (nextCFA , context ) ? new LinuxAMD64CFrame (dbg , nextCFA , nextPC , nextDwarf , false , fallback )
170173 : null ;
171174 }
172175
176+ private DwarfParser createDwarfParser (Address pc ) throws DebuggerException {
177+ DwarfParser nextDwarf = null ;
178+ Address libptr = dbg .findLibPtrByAddress (pc );
179+ if (libptr != null ) {
180+ try {
181+ nextDwarf = new DwarfParser (libptr );
182+ } catch (DebuggerException _) {
183+ // Bail out to Java frame
184+ }
185+ }
186+
187+ if (nextDwarf != null ) {
188+ nextDwarf .processDwarf (pc );
189+ }
190+
191+ return nextDwarf ;
192+ }
193+
173194 // package/class internals only
174195 private static final int ADDRESS_SIZE = 8 ;
175196 private Address rip ;
176197 private Address cfa ;
177198 private LinuxDebugger dbg ;
178199 private DwarfParser dwarf ;
179200 private boolean finalFrame ;
201+ private boolean use1ByteBeforeToLookup ;
180202}
0 commit comments