Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > breakpoints

Reply
Thread Tools

breakpoints

 
 
Andrey Vul
Guest
Posts: n/a
 
      10-27-2009
Is there a way to set breakpoints without relying on platforms /
compilers or relying on nasal demons?

By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
NULL) = 0; }
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      10-27-2009
Andrey Vul <> writes:
> Is there a way to set breakpoints without relying on platforms /
> compilers or relying on nasal demons?


No. The C language has no concept of breakpoints; anything you do to
set one therefore has to be system-specific.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      10-27-2009
On Oct 26, 5:26*pm, Andrey Vul <andrey....@gmail.com> wrote:
> Is there a way to set breakpoints without relying on platforms /
> compilers or relying on nasal demons?
>
> By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
> NULL) = 0; }


The closest thing in the C language is:
abort();

You may also enjoy:
assert(0);

HTH
 
Reply With Quote
 
Andrey Vul
Guest
Posts: n/a
 
      10-27-2009
On Oct 26, 8:35*pm, user923005 <dcor...@connx.com> wrote:
> On Oct 26, 5:26*pm, Andrey Vul <andrey....@gmail.com> wrote:
>
> > Is there a way to set breakpoints without relying on platforms /
> > compilers or relying on nasal demons?

>
> > By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
> > NULL) = 0; }

>
> The closest thing in the C language is:
> *abort();
>
> You may also enjoy:
> *assert(0);
>
> HTH

Not really.
exit != enter debugger
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      10-27-2009
On Oct 26, 7:03*pm, Andrey Vul <andrey....@gmail.com> wrote:
> On Oct 26, 8:35*pm, user923005 <dcor...@connx.com> wrote:> On Oct 26, 5:26*pm, Andrey Vul <andrey....@gmail.com> wrote:
>
> > > Is there a way to set breakpoints without relying on platforms /
> > > compilers or relying on nasal demons?

>
> > > By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
> > > NULL) = 0; }

>
> > The closest thing in the C language is:
> > *abort();

>
> > You may also enjoy:
> > *assert(0);

>
> > HTH

>
> Not really.
> exit != enter debugger


Depends on your compiler. Both of these will take me right to the
spot with some of the compilers I use.

However, if you want something that is standard and guaranteed to take
you right to a spot in the code, then you will have a bit of a sticky
wicket, I think.
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      10-27-2009
On 2009-10-27, Andrey Vul <> wrote:
> Not really.
> exit != enter debugger


Right, but see, there's no standard debugger AT ALL, so no interaction
with the debugger is standardized.

The breakpoint() trick is likely, the other thing you can do is just
set breakpoints where you want them. A good debugger can likely turn
specific points on and off automatically, etc.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-27-2009
Andrey Vul wrote:
> On Oct 26, 8:35�pm, user923005 <dcor...@connx.com> wrote:
>> On Oct 26, 5:26�pm, Andrey Vul <andrey....@gmail.com> wrote:
>>
>>> Is there a way to set breakpoints without relying on platforms /
>>> compilers or relying on nasal demons?
>>> By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
>>> NULL) = 0; }

>> The closest thing in the C language is:
>> �abort();
>>
>> You may also enjoy:
>> �assert(0);
>>
>> HTH

> Not really.
> exit != enter debugger


I think you're missing the point. C doesn't provide any method for
entering the debugger, so the fact that neither abort() nor assert()
have that effect doesn't prevent them from being "the closest thing in
the C language". Both of them halt processing at the specified location,
which is the only aspect of a breakpoint which CAN be simulated within C
itself.

Finally, on some systems, all you have to do to examine the current
state of the program after a call to abort() is to load the 'core' file
which may have been created as a side-effect of the abort() call, into a
debugger, which again makes this "the closest thing in the C language"
to setting up a break point.
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      10-27-2009
Andrey Vul wrote:

> Is there a way to set breakpoints without relying on platforms /
> compilers or relying on nasal demons?
>
> By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
> NULL) = 0; }


Why do you wish to use the breakpoints feature without the help of a debugger?


Rui Maciel
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      10-27-2009
Andrey Vul a écrit :
> Is there a way to set breakpoints without relying on platforms /
> compilers or relying on nasal demons?
>
> By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
> NULL) = 0; }


In the x86 type machines you can insert a breakpoint
instruction (int 3) in the code

typedef void (*voidfn)(void);
void breakpoint(void)
{
// int 3 is 0xcc
char * code = "\xcc";
voidfn fn = (voidfn)code;
fn();
}

This supposes that your operating system calls a registered debugger when it sees
an int 3.
In other CPUs that have a breakpoint instruction you can change the opcode.

Another (more portable) way is:

void breakpoint(void)
{
fprintf(stderr,"Breakpoint reached. Calling the debugger\n");
fflush(stderr);
system("My Path To The debugger with appropiate parameters\n");
}

This supposes that your debugger can attach to a running process. Most
debuggers do.
 
Reply With Quote
 
Michael Schumacher
Guest
Posts: n/a
 
      10-27-2009
Andrey Vul wrote:

> On Oct 26, 8:35Â*pm, user923005 <dcor...@connx.com> wrote:
>> On Oct 26, 5:26Â*pm, Andrey Vul <andrey....@gmail.com> wrote:
>>
>> > Is there a way to set breakpoints without relying on platforms /
>> > compilers or relying on nasal demons?

>>
>> > By nasal demons, I mean this one-liner: void breakpoint() { *((char *)
>> > NULL) = 0; }

>>
>> The closest thing in the C language is:
>> abort();
>>
>> You may also enjoy:
>> assert(0);
>>
>> HTH

> Not really.
> exit != enter debugger


Ah, that makes things clearer. There's no "standard" way whatsoever
to call a debugger from compiled C code, but provided your program
runs under control of a debugger (or at least a monitor that talks
to a debugger), and you want the program control transferred to the
debugger at specific points, you can do this:

#ifdef CHECKPOINTS
static void checkpoint (void) { /* empty */ }
#define CHECKPT do { checkpoint (); } while (0);
#else
#define CHECKPT /* empty */
#endif

You should put this in a header file (say, "checkpt.h") and #include
it in all C modules where you want to apply checkpoints (of course,
you'll later have to recompile them with "-DCHECKPOINTS").

Then, insert "CHECKPT"s in your C code wherever you deem them right,
and set an actual breakpoint from within the debugger to "checkpoint"
(usually before you start the program). If your program hits such a
CHECKPT, the debugger will re-gain control, and you will have to use
its "one frame up"-command to set the context to the causing CHECKPT.
With gdb, you can easily automate this by attaching an "up" command
to the "checkpoint" breakpoint from within a command file (.gdbinit).

Since breakpoints (and breakpoint handling) depend on so many things
(monitor, debugger, target architecture, target OS, memory type and
memory protection, a.s.o.), I think this approach is the closest you
can get to "independent breakpoints". I'd really appreciate it if
someone could prove me wrong on this, but I doubt this will actually
happen...


Cheers,
mike

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Broken breakpoints and symbols not loading Shawn South ASP .Net 0 08-16-2004 05:56 PM
VS.net breakpoints Dave ASP .Net 3 12-04-2003 04:58 PM
can't debug asp.net; won't stop at breakpoints Brent Burkart ASP .Net 0 10-27-2003 10:55 PM
ASP.NET ignoring all breakpoints Ron Icard ASP .Net 1 08-22-2003 08:23 PM
Debugging problems in .NET...breakpoints never hit. Doug Swanson ASP .Net 5 07-28-2003 08:57 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57