Generally, how to debug inside MSCRTD.DLL ? 
Author Message
 Generally, how to debug inside MSCRTD.DLL ?

No-brainer problem, but I need some help:

Simple string token scanner, using strtok(), is crashing (access
violation) inside the C run-time library.  How do folks usually debug
this?  I don't want to debug this at assembler-level inside the library.

My calling sequence looks correct, and, in fact, I can run this code on
Unix (compiled as a .c program).  In Visual Studio 6.0, I am compiling
it as a .cpp

Actual code is a command line parser inside a DLL,
but here is dirt-simple distilled example code (which crashes too):

     #include "stdafx.h"

     char * s = "now is the time for all good men to vote\n";
     const char * seps = " \t\n";

     int main(int argc, char* argv[])
     {
     int n;
     char * p; /* token */

      n = 0;
      /* establish string and get the first token: */
      p = strtok(s, seps );                                    /*
     <== crashes on first invocation */
      while( p != NULL ) /* more tokens */
      {
           p = strtok( NULL, seps ); /* get next token */
      }
      return 0;
     }

George P. Cotsonas
Motorola, Inc.



Sun, 27 Apr 2003 03:00:00 GMT  
 Generally, how to debug inside MSCRTD.DLL ?
Your string needs to be an array of char

works as
char s[50] = "now is the time for all good men to vote\n";

Dave

Quote:
-----Original Message-----
No-brainer problem, but I need some help:

Simple string token scanner, using strtok(), is crashing (access
violation) inside the C run-time library.  How do folks usually debug
this?  I don't want to debug this at assembler-level inside the library.

My calling sequence looks correct, and, in fact, I can run this code on
Unix (compiled as a .c program).  In Visual Studio 6.0, I am compiling
it as a .cpp

Actual code is a command line parser inside a DLL,
but here is dirt-simple distilled example code (which crashes too):

     #include "stdafx.h"

     char * s = "now is the time for all good men to vote\n";
     const char * seps = " \t\n";

     int main(int argc, char* argv[])
     {
     int n;
     char * p; /* token */

      n = 0;
      /* establish string and get the first token: */
      p = strtok(s, seps );                                    /*
     <== crashes on first invocation */
      while( p != NULL ) /* more tokens */
      {
           p = strtok( NULL, seps ); /* get next token */
      }
      return 0;
     }

George P. Cotsonas
Motorola, Inc.



Sun, 27 Apr 2003 03:00:00 GMT  
 Generally, how to debug inside MSCRTD.DLL ?
The problem is that VC puts string literals in read-only memory.  Your char
* s is pointing to a string literal (which is technically const).  strtok
actually changes the string, which causes your access violation.

You solve this by not using a string literal like that.  Use an array of
char.



Quote:
> No-brainer problem, but I need some help:

> Simple string token scanner, using strtok(), is crashing (access
> violation) inside the C run-time library.  How do folks usually debug
> this?  I don't want to debug this at assembler-level inside the library.

> My calling sequence looks correct, and, in fact, I can run this code on
> Unix (compiled as a .c program).  In Visual Studio 6.0, I am compiling
> it as a .cpp

> Actual code is a command line parser inside a DLL,
> but here is dirt-simple distilled example code (which crashes too):

>      #include "stdafx.h"

>      char * s = "now is the time for all good men to vote\n";
>      const char * seps = " \t\n";

>      int main(int argc, char* argv[])
>      {
>      int n;
>      char * p; /* token */

>       n = 0;
>       /* establish string and get the first token: */
>       p = strtok(s, seps );                                    /*
>      <== crashes on first invocation */
>       while( p != NULL ) /* more tokens */
>       {
>            p = strtok( NULL, seps ); /* get next token */
>       }
>       return 0;
>      }

> George P. Cotsonas
> Motorola, Inc.



Mon, 28 Apr 2003 03:00:00 GMT  
 Generally, how to debug inside MSCRTD.DLL ?
Thanks for the feedback, but in the actual application,
I am passing an LPSTR pointer argument to the parser function.
Therefore, do not think I am pointing to a const string.
Getting access violation or page fault.

Any other thoughts would be appreciated.

George



Mon, 28 Apr 2003 03:00:00 GMT  
 Generally, how to debug inside MSCRTD.DLL ?
In short, change this:

char * s = "now is the time for all good men to vote\n";

to this:

char s[] = "now is the time for all good men to vote\n";

While you're at it - install the C run time source. You don't
need to debug through it in assembly mode.

Quote:

> The problem is that VC puts string literals in read-only memory.  Your char
> * s is pointing to a string literal (which is technically const).  strtok
> actually changes the string, which causes your access violation.

> You solve this by not using a string literal like that.  Use an array of
> char.



> > No-brainer problem, but I need some help:

> > Simple string token scanner, using strtok(), is crashing (access
> > violation) inside the C run-time library.  How do folks usually debug
> > this?  I don't want to debug this at assembler-level inside the library.

> > My calling sequence looks correct, and, in fact, I can run this code on
> > Unix (compiled as a .c program).  In Visual Studio 6.0, I am compiling
> > it as a .cpp

> > Actual code is a command line parser inside a DLL,
> > but here is dirt-simple distilled example code (which crashes too):

> >      #include "stdafx.h"

> >      char * s = "now is the time for all good men to vote\n";
> >      const char * seps = " \t\n";

> >      int main(int argc, char* argv[])
> >      {
> >      int n;
> >      char * p; /* token */

> >       n = 0;
> >       /* establish string and get the first token: */
> >       p = strtok(s, seps );                                    /*
> >      <== crashes on first invocation */
> >       while( p != NULL ) /* more tokens */
> >       {
> >            p = strtok( NULL, seps ); /* get next token */
> >       }
> >       return 0;
> >      }

> > George P. Cotsonas
> > Motorola, Inc.

--
.Bruce Dawson, Humongous Entertainment (we're hiring).
http://www.humongous.com/
Send job applications by e-mail, post technical questions
to the newsgroups please. Thanks.


Mon, 28 Apr 2003 03:00:00 GMT  
 Generally, how to debug inside MSCRTD.DLL ?

According to my research, you can solve the problem as the following:

Original:
char * s = "now is the time for all good men to vote";
const char *seps = " \t\n";

Change to:
char s[] = "now is the time for all good men to vote";
const char seps[] = " \t\n";

It will work.



Sat, 03 May 2003 15:22:02 GMT  
 Generally, how to debug inside MSCRTD.DLL ?

About how to debug inside :

1. set a break point at the routine of MSCRTD.DLL.
2. Debug the applicatiuon.
3. When you arrive the breakpoint, select the meny "Debug"->"Start
Debug"->"Step into" or press the key F11.
4. You will debug into the source code of the dll.



Sat, 03 May 2003 15:28:45 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Debug infos inside the EXE ??

2. generally pointers

3. Debugging Inside a Function

4. Generally curious

5. allocator and GC locality, and locality generally (was Re: cost of malloc)

6. debugging exe's inside a frame

7. building static lib with debug info inside

8. How to send mail generally?

9. building static lib with debug info inside

10. Which is generally faster?

11. Debugging code linked to non-debug versions of DLLs

12. Debigging non-debug process and debug DLL

 

 
Powered by phpBB® Forum Software