* bfinish writes to random addresses. @ 2006-07-25 15:41 Greg Law 2006-07-25 15:42 ` Daniel Jacobowitz 0 siblings, 1 reply; 8+ messages in thread From: Greg Law @ 2006-07-25 15:41 UTC (permalink / raw) To: gdb Hi list, When doing a 'finish' command when EBP contains bad values such that gdb gets confused about a function's return address, it writes a breakpoint into an essentially random point in the inferior's address space. Should I report a bug, or do we consider it the user's own stupid fault if he/she tries to do a 'finish' command when the frame-pointer is invalid? Cheers, Greg -- Greg Law, Undo Software http://undo-software.com/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 15:41 bfinish writes to random addresses Greg Law @ 2006-07-25 15:42 ` Daniel Jacobowitz 2006-07-25 16:09 ` Greg Law 0 siblings, 1 reply; 8+ messages in thread From: Daniel Jacobowitz @ 2006-07-25 15:42 UTC (permalink / raw) To: Greg Law; +Cc: gdb On Tue, Jul 25, 2006 at 04:39:15PM +0100, Greg Law wrote: > Hi list, > > When doing a 'finish' command when EBP contains bad values such that gdb > gets confused about a function's return address, it writes a breakpoint > into an essentially random point in the inferior's address space. > > Should I report a bug, or do we consider it the user's own stupid fault > if he/she tries to do a 'finish' command when the frame-pointer is invalid? Well, is there anything better that could be done about it? I don't think so. Finish is going to take you back to whatever GDB thinks the previous frame is. Now, of course, GDB shouldn't get confused in the first place. That's always worth filing a bug about, although it may be a case of inadequate debug information or other similar problems out of our control. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 15:42 ` Daniel Jacobowitz @ 2006-07-25 16:09 ` Greg Law 2006-07-25 16:20 ` Daniel Jacobowitz 0 siblings, 1 reply; 8+ messages in thread From: Greg Law @ 2006-07-25 16:09 UTC (permalink / raw) To: Daniel Jacobowitz; +Cc: gdb Daniel Jacobowitz wrote: > On Tue, Jul 25, 2006 at 04:39:15PM +0100, Greg Law wrote: > >>Hi list, >> >>When doing a 'finish' command when EBP contains bad values such that gdb >>gets confused about a function's return address, it writes a breakpoint >>into an essentially random point in the inferior's address space. >> >>Should I report a bug, or do we consider it the user's own stupid fault >>if he/she tries to do a 'finish' command when the frame-pointer is invalid? > > > Well, is there anything better that could be done about it? I guess one option would be to use a hardware breakpoint when setting breakpoints based on such "derived" addresses. At least that way it's non-destructive if gdb gets it wrong. Having gdb check the return address looks like a sensible code address might also be worthwhile. Of course this will not fix all cases, especially if the calculated return address happens to point into the middle of an instruction. But hopefully in reality most things that look like pointers to code will actually be pointers to code, and so properly aligned, and the breakpoint will just go to the wrong place, rather than clobbering random data. > I don't > think so. Finish is going to take you back to whatever GDB thinks the > previous frame is. > > Now, of course, GDB shouldn't get confused in the first place. That's > always worth filing a bug about, although it may be a case of > inadequate debug information or other similar problems out of our > control. In the particular case I'm looking at I think it's reasonable that gdb gets the return address wrong. It's some assembler code that clobbers EBP. My concern was more gdb's ability to clobber arbitrary inferior addresses, and the subtle problems this might lead to. g -- Greg Law, Undo Software http://undo-software.com/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 16:09 ` Greg Law @ 2006-07-25 16:20 ` Daniel Jacobowitz 2006-07-25 16:27 ` Greg Law 0 siblings, 1 reply; 8+ messages in thread From: Daniel Jacobowitz @ 2006-07-25 16:20 UTC (permalink / raw) To: Greg Law; +Cc: gdb On Tue, Jul 25, 2006 at 05:01:30PM +0100, Greg Law wrote: > I guess one option would be to use a hardware breakpoint when setting > breakpoints based on such "derived" addresses. At least that way it's > non-destructive if gdb gets it wrong. Every address where GDB sets any breakpoint is "derived" in that sense. And there aren't very many hardware breakpoints, if any. > Having gdb check the return address looks like a sensible code address > might also be worthwhile. Of course this will not fix all cases, > especially if the calculated return address happens to point into the > middle of an instruction. But hopefully in reality most things that > look like pointers to code will actually be pointers to code, and so > properly aligned, and the breakpoint will just go to the wrong place, > rather than clobbering random data. ... Properly aligned? You're talking about %ebp so I assume you're talking about x86, and instructions have no alignment on this architecture. Warning when returning from something with a symbol to something without a symbol is an interesting suggestion. Does anyone else have comments? Should this warn? (gdb) bt #0 foo() #1 0x4000000 in ??? (gdb) finish -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 16:20 ` Daniel Jacobowitz @ 2006-07-25 16:27 ` Greg Law 2006-07-25 16:53 ` Daniel Jacobowitz 2006-07-25 18:40 ` Mark Kettenis 0 siblings, 2 replies; 8+ messages in thread From: Greg Law @ 2006-07-25 16:27 UTC (permalink / raw) To: Daniel Jacobowitz, gdb Daniel Jacobowitz wrote: > On Tue, Jul 25, 2006 at 05:01:30PM +0100, Greg Law wrote: > >>I guess one option would be to use a hardware breakpoint when setting >>breakpoints based on such "derived" addresses. At least that way it's >>non-destructive if gdb gets it wrong. > > > Every address where GDB sets any breakpoint is "derived" in that sense. What I meant was if the address comes from looking up a symbol or some such, then it seems reasonable to have more confidence in it being correct. As opposed to an address derived from program state -- namely function return addresses. > And there aren't very many hardware breakpoints, if any. At least in the cases I've seen on x86, most of the time the hardware breakpoints aren't in use. Of course, on other architectures there may be none, and on x86 they may all be used. But my point was that if a hardware breakpoint is used if available, it would fix this at least in those cases. Maybe this is considered sufficiently unusual, or a user trying to do such a thing is considered sufficiently stupid that it isn't considered worth the effort. But I alas I was sufficiently stupid, and it did take quite a while to track down what was going on here. > > >>Having gdb check the return address looks like a sensible code address >>might also be worthwhile. Of course this will not fix all cases, >>especially if the calculated return address happens to point into the >>middle of an instruction. But hopefully in reality most things that >>look like pointers to code will actually be pointers to code, and so >>properly aligned, and the breakpoint will just go to the wrong place, >>rather than clobbering random data. > > > ... Properly aligned? You're talking about %ebp so I assume you're > talking about x86, and instructions have no alignment on this > architecture. Sorry, bad terminology from me. What I meant was that if there is a word in memory that is an address in a text segment, then chances are it is a pointer to some instruction, so most likely it points at the beginning of the instruction, not into the middle of an instruction. > > Warning when returning from something with a symbol to something > without a symbol is an interesting suggestion. Does anyone else have > comments? Should this warn? > > (gdb) bt > #0 foo() > #1 0x4000000 in ??? > (gdb) finish > I was actually suggesting an error rather than a warning. In this case, it seems that writing into 0x40000000 is almost certainly not what the user wants gdb to be doing. Greg -- Greg Law, Undo Software http://undo-software.com/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 16:27 ` Greg Law @ 2006-07-25 16:53 ` Daniel Jacobowitz 2006-07-25 18:40 ` Mark Kettenis 1 sibling, 0 replies; 8+ messages in thread From: Daniel Jacobowitz @ 2006-07-25 16:53 UTC (permalink / raw) To: Greg Law; +Cc: gdb On Tue, Jul 25, 2006 at 05:24:32PM +0100, Greg Law wrote: > >Warning when returning from something with a symbol to something > >without a symbol is an interesting suggestion. Does anyone else have > >comments? Should this warn? > > > >(gdb) bt > >#0 foo() > >#1 0x4000000 in ??? > >(gdb) finish > > > > I was actually suggesting an error rather than a warning. In this case, > it seems that writing into 0x40000000 is almost certainly not what the > user wants gdb to be doing. Surprisingly often it is. We need to be sparing with errors. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 16:27 ` Greg Law 2006-07-25 16:53 ` Daniel Jacobowitz @ 2006-07-25 18:40 ` Mark Kettenis 2006-07-26 1:21 ` Daniel Jacobowitz 1 sibling, 1 reply; 8+ messages in thread From: Mark Kettenis @ 2006-07-25 18:40 UTC (permalink / raw) To: Greg Law; +Cc: Daniel Jacobowitz, gdb > Daniel Jacobowitz wrote: > > > And there aren't very many hardware breakpoints, if any. > > At least in the cases I've seen on x86, most of the time the hardware > breakpoints aren't in use. Of course, on other architectures there may > be none, and on x86 they may all be used. But my point was that if a > hardware breakpoint is used if available, it would fix this at least in > those cases. If you can come up with some code that doesn't compicate matters too much and falls back on the software breakpoints if no hardware breakpoints are available, that might be a good idea. > Maybe this is considered sufficiently unusual, or a user trying to do > such a thing is considered sufficiently stupid that it isn't considered > worth the effort. But I alas I was sufficiently stupid, and it did take > quite a while to track down what was going on here. Well, I's probably a good idea to look before you jump. Otherwise you might land in deep shit! ;-) > Sorry, bad terminology from me. What I meant was that if there is a > word in memory that is an address in a text segment, then chances are it > is a pointer to some instruction, so most likely it points at the > beginning of the instruction, not into the middle of an instruction. Well, there are quite a few cases where programs execute code outside the text segment. GCC for example, creates trampolines on the stack for nested functions. A better approach would be to look wheter a page at a particular address is "executable". But in general that information is not available to GDB. > > Warning when returning from something with a symbol to something > > without a symbol is an interesting suggestion. Does anyone else have > > comments? Should this warn? > > > > (gdb) bt > > #0 foo() > > #1 0x4000000 in ??? > > (gdb) finish > > > > I was actually suggesting an error rather than a warning. In this case, > it seems that writing into 0x40000000 is almost certainly not what the > user wants gdb to be doing. This situation can arise easily if only partial debug information is available. I think that even a warning would be annoying. Mark ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bfinish writes to random addresses. 2006-07-25 18:40 ` Mark Kettenis @ 2006-07-26 1:21 ` Daniel Jacobowitz 0 siblings, 0 replies; 8+ messages in thread From: Daniel Jacobowitz @ 2006-07-26 1:21 UTC (permalink / raw) To: Mark Kettenis; +Cc: Greg Law, gdb On Tue, Jul 25, 2006 at 08:22:20PM +0200, Mark Kettenis wrote: > > Daniel Jacobowitz wrote: > > > > > And there aren't very many hardware breakpoints, if any. > > > > At least in the cases I've seen on x86, most of the time the hardware > > breakpoints aren't in use. Of course, on other architectures there may > > be none, and on x86 they may all be used. But my point was that if a > > hardware breakpoint is used if available, it would fix this at least in > > those cases. > > If you can come up with some code that doesn't compicate matters too much > and falls back on the software breakpoints if no hardware breakpoints are > available, that might be a good idea. Fortunately, we already need code to do this sort of thing - and it's one of those issues that we (at CS) are going to be taking a look at this year, time permitting. This is just the reverse of trying to use a software breakpoint when debugging ROM, and the same approach will work. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-07-25 18:40 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-07-25 15:41 bfinish writes to random addresses Greg Law 2006-07-25 15:42 ` Daniel Jacobowitz 2006-07-25 16:09 ` Greg Law 2006-07-25 16:20 ` Daniel Jacobowitz 2006-07-25 16:27 ` Greg Law 2006-07-25 16:53 ` Daniel Jacobowitz 2006-07-25 18:40 ` Mark Kettenis 2006-07-26 1:21 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox