Lazarus debugger fails to work with PIE binaries
Original Reporter info from Mantis: norayr
-
Reporter name: Norayr Chilingarian
Original Reporter info from Mantis: norayr
- Reporter name: Norayr Chilingarian
Description:
In the beginning, Lazarus ide calls gdb with an "info address main" command and sets a breakpoint with an address, not the name.
---
(gdb)
&LtPos;info address main>
&"info address main\n"
~"Symbol "main" is a function at address 0x724.\n"
^done
(gdb)
<-break-insert -t *1828>
---
Later, when PIE elf is loaded that address changes and that's why debugging fails.
---
(gdb)
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
^error,msg="Warning:\nCannot insert breakpoint 1.\nError accessing memory address 0x724: Input/output error.\n"
(gdb)
---
It seems that the beginning of the SetTempMainBreak function of the GDBMIDebugger may be removed:
---
// Try to retrieve the address of main. Setting a break on main is past initialization
if ExecuteCommand('info address main', R)
and (R.State <> dsError)
then begin
S := GetPart(['at address ', ' at '], ['.', ' '], R.Values);
if S <> ''
then begin
FTheDebugger.FMainAddr := StrToQWordDef(S, 0);
ExecuteCommand('-break-insert -t *%u', [FTheDebugger.FMainAddr], R);
Result := R.State <> dsError;
if Result then Exit;
end;
end;
---
Because later it calls
ExecuteCommand('-break-insert -t main', R);
which works with PIE elf files ok.
FTheDebugger.FMainAddr seem to not be used, so that change may be the right solution.
Steps to reproduce:
debug a pie executable.
Additional information:
we found out this by debugging apache module which is pie because apache is pie in rhel6
Mantis conversion info:
- Mantis ID: 21106
- OS: GNU/Linux
- OS Build: RHEL6
- Platform: x86_64
- Version: 0.9.31 (SVN)
- Fixed in version: 0.9.31 (SVN)
- Fixed in revision: 34811 (#fbb30771)
- Monitored by: » norayr (Norayr Chilingarian)
- Target version: 0.99.0
- LazTarget: 1.0