473,883 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debugging standard C library routines

I am working on MontaVista Linux on a PPC board.
The compiler I am using is a gnu cross compiler cross compiler
(ppc-82xx-gcc)

The application/software that is being run, is messing up the memory
due to which a subsequent malloc fails.

When the application core is dumped I do not get any backtrace in the
code (although the application is compiled with debug symbols, with -g
option). The only thing I get is the address of the function (and not
the name) where the crash is happening.

Using prints in the code I found that application crashes while calling
malloc. I am linking the standard C library as .so, and thats probably
why there is not backtrace conatining the functions of my application.

There is not enough memory on the board to run gdb. Also due to the
complexity of the scenarios it is not always possible to run gdbserver.
It there a possible way to:
1. Link a debuggable version of stdlib which would put more information
in the core, when it is dumped.
2. Can I enable some asserts or extra information in stdlib which would
tell me if memry is being messed up.
3. Is there a way by which I can map an address to a function of .so
loaded in the memory. Or even if i know that the address belongs t a
perticaular .so

Thanks in advance.

Sep 30 '06
83 4014
Richard Heathfield wrote:
Great example. Well done. If you omit the initialisation, okay, let's say
the compiler issues a warning (despite the fact that it needn't and some
don't). But you know and I know that some people will say "oh, it's only a
warning, it's fine", and they'll be scratching their heads trying to debug
it.
Do people really ignore the warning "use of uninitialized variable",
when trying to debug a piece of code that produces that warning
and is behaving strangely?
Whereas, if you set q to NULL, then it doesn't take a genius to
discover that *start is being set to an obviously silly value (probably
NULL, possibly 1). So the debugging process is very swift after all.
It can be a slow process, when working on an embedded device
where writing to low-numbered addresses causes the thing to crap
itself and take you several minutes to reload everything... (recall
my *dest++ = *src++ bug)

Oct 14 '06 #71
Christopher Layne wrote:
I personally despise this C++/"declare on a whim" style. I like to know what
I'm getting into when I read over a function - and a function which has it's
table of contents spread out and buried within individual chapters just
pisses me off more than it helps anything.
Worst analogy of the week.

Why would you possibly care which variables a function uses,
unless you are coding to tight stack requirements?

Further, why would you try and deduce a function's activities by
reading its list of variables? Surely it would be better to read the
comments, or observe the code structure.

Oct 14 '06 #72
Frederick Gotham wrote:
#include <stddef.h>
#include <stdlib.h>

void *ExitiveMalloc( size_t const size)
{
void *const p = malloc(size);
if(!p) exit(EXIT_FAILU RE);
return p;
}

Here's an example of where I'd be wreckless with malloc:
You wouldn't cause any wrecks? Are you sure?
#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>

char *const TruncateAndMake Uppercase(char const *const arg,size_t const len)
{
int const assert_dummy = (assert(!!arg), 0);
Is this supposed to be an improvement on:
assert(arg);

? And what is the '!!' doing?
char *const retval=ExitiveM alloc(len+1), *p=retval;
ExitiveMalloc exits if it fails to allocate. So this code is not
reckless with failing to check the return value of malloc.
strncpy(retval, arg,len);
Does not 0-terminate the string in some cases
(so the attempt to iterate over the string would cause
a buffer overflow).
while( *p++ = toupper((char unsigned)*p) );
Undefined behaviour. What if 'p' is incremented before
being evaluated for dereferencign to pass to 'toupper' ?
return (void)assert_du mmy, retval;
Huh?
}
You cannot assert that the code is stupid unless you know the details of the
project.
I, for one, would not hesitate to call this function stupid.

Oct 14 '06 #73
Old Wolf said:
Richard Heathfield wrote:
>Great example. Well done. If you omit the initialisation, okay, let's say
the compiler issues a warning (despite the fact that it needn't and some
don't). But you know and I know that some people will say "oh, it's only
a warning, it's fine", and they'll be scratching their heads trying to
debug it.

Do people really ignore the warning "use of uninitialized variable",
when trying to debug a piece of code that produces that warning
and is behaving strangely?
I'm sorry, but yes, they do. I'm astounded at the warnings people are
prepared to ignore. I've even seen people try to ignore syntax errors.
>Whereas, if you set q to NULL, then it doesn't take a genius to
discover that *start is being set to an obviously silly value (probably
NULL, possibly 1). So the debugging process is very swift after all.

It can be a slow process, when working on an embedded device
where writing to low-numbered addresses causes the thing to crap
itself and take you several minutes to reload everything... (recall
my *dest++ = *src++ bug)
I don't see how writing to random addresses would help you speed things up!
But this is Yet Another Advantage of writing portable code - you can catch
such silly bugs on a desktop platform, and only move code to the bitty-box
when you know it stands a fighting chance of being right.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 15 '06 #74
Old Wolf said:
Frederick Gotham wrote:
<snip>
>char *const TruncateAndMake Uppercase(char const *const arg,size_t const
len)
{
int const assert_dummy = (assert(!!arg), 0);

Is this supposed to be an improvement on:
assert(arg);
Well, it's obviously a lousy idea, but yes, there's an improvement in
there...
>
? And what is the '!!' doing?
Making the assertion arg an integer expression rather than a pointer
expression, and thus keeping the behaviour well-defined in C90.

<snip>
I, for one, would not hesitate to call this function stupid.
Nevertheless (and whether by accident or design), it taught you something
about assert(). :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 15 '06 #75
Old Wolf posted:
Christopher Layne wrote:
>I personally despise this C++/"declare on a whim" style. I like to know
what I'm getting into when I read over a function - and a function
which has it's table of contents spread out and buried within
individual chapters just pisses me off more than it helps anything.

Worst analogy of the week.

Why would you possibly care which variables a function uses,
unless you are coding to tight stack requirements?

Further, why would you try and deduce a function's activities by
reading its list of variables? Surely it would be better to read the
comments, or observe the code structure.

While we're talking about literature... would you prefer if each character
was described on the first page of the first chapter, or would you prefer if
each consecutive character were introduced to the reader as the plot
develops?

--

Frederick Gotham
Oct 15 '06 #76
Old Wolf posted:
> int const assert_dummy = (assert(!!arg), 0);

Is this supposed to be an improvement on:
assert(arg);

You can't mix statements and declarations in C (within a block).

? And what is the '!!' doing?

The argument to "assert" must be of the type, int.

> strncpy(retval, arg,len);

Does not 0-terminate the string in some cases
(so the attempt to iterate over the string would cause
a buffer overflow).

I'll have to read up on that function.

> while( *p++ = toupper((char unsigned)*p) );

Undefined behaviour. What if 'p' is incremented before
being evaluated for dereferencign to pass to 'toupper' ?

Are you sure that a sequence point has been violated?

> return (void)assert_du mmy, retval;

Huh?

The cast-to-void is intended to suppress a compiler warning regarding non-
usage of a variable.

--

Frederick Gotham
Oct 15 '06 #77
Old Wolf posted:
If the pointer is subsequently reassigned-to, or not used again before
its lifetime ends, then setting to NULL will be optimised out.

The Standard does not impose such a restriction.

If the pointer is dereferenced instead, then you have undefined
behaviour anyway, so what does a few nanoseconds matter?

Finally, if your pointer is global, then a pox on you.

A pox on your naivety. A programmer who hasn't found a use for a global
pointer is like a grown adult who hasn't found a use for one of the many
tools he was told to avoid as a kid... blow tourches, knives, drills, bleach.

I've been programming long enough to make my own decisions.

--

Frederick Gotham
Oct 15 '06 #78
Frederick Gotham wrote:
Old Wolf posted:
.... snip ...
>>
Further, why would you try and deduce a function's activities by
reading its list of variables? Surely it would be better to read
the comments, or observe the code structure.

While we're talking about literature... would you prefer if each
character was described on the first page of the first chapter, or
would you prefer if each consecutive character were introduced to
the reader as the plot develops?
Both Shakespeare and Erle Stanley Gardner used a "Dramatis
Personnae" section. Very handy.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Oct 15 '06 #79
CBFalconer posted:
Both Shakespeare and Erle Stanley Gardner used a "Dramatis
Personnae" section. Very handy.

There's nothing to stop someone doing something like:
void Func()
{
/* This function defines the following local objects:

int i; To hold the amount of chickens
double r; To hold the mean mass of a chicken
*/
/* ... Now define them however you please... */
}

--

Frederick Gotham
Oct 15 '06 #80

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4944
by: Advocated | last post by:
Hi there, just wondering if anyone uses visual studio 6? Im having real problems, just with debugging, i could either do with a really good tutorial, if anyone knows of one, but the main thing is, when i run the debugger, as soon as it gets to my first printf statement, its asking me "please enter the path for PRINTF.C" Any ideas?
10
3682
by: ibic | last post by:
Just curious: is it possible to recursively list all the directorys/files inside a given directory using standard c i/o library routines only, which can be re-compiled and run on any os supportes c compiler? Or this is too os dependent, system-specific functions must be called? I think about this when i tried to do this under windows, i found in order to achieve this, some windows-specific api such as FindFirstFile, FindNextFile must be...
4
7070
by: yinglcs | last post by:
I am trying to debug a C++ program in GDB on linux. I want to dump out the content of the "this" object, Here is what I get: (gdb) print *this $2 = {path = <incomplete type>} My question is why I don't see the content of 'path'? It said '<incomplete type>'. In the code, path is:
22
2522
by: David Mathog | last post by:
One thing that keeps coming up in this forum is that standard C lacks many functions which are required in a workstation or server but not possible in an embedded controller. This results in a plethora of "don't ask here, ask in comp.x.y instead", for queries on functions that from the documentation available to the programmer appear to be part of the C language. I think largely because of this "least common denominator" C language...
85
4894
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C standard. My question now is: Is there a chance that such statement will become a part of C standard in the future? In some cases using asm language is the best way to acomplish some small task, hence integration of C and asm would greatly enhence C,...
5
7805
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an app.config file referencing arbitrary versions of the plug-in components they wish to consume. Here's the problem: Assuming I have installed any one of our application software,
20
3549
by: J de Boyne Pollard | last post by:
MThe library functions which are included to allow process Mlaunch, forking, and termination, imply that it is both Mpossible and desirable for a process to fork itself. This is Ma fundamental part of the Unix thought process, but is Mnot essential for a working OS. There are no Standard C Library functions for process forking or overlaying. The fork() and execve() functions are part of the C language bindings to POSIX. They are not...
6
2266
by: Jeff | last post by:
I understand there's socket / recursive calls here, but this is a C question, really it is: Here's the code block in question: #if defined(__GLIBC__) { struct hostent hent; char hbf; memset(&hbf, '\0', 8192);
33
2893
by: fmassei | last post by:
Hello! I made a short piece of code that I find very useful for debugging, and I wanted to ask you if it is correct, somehow acceptable or if I simply reinvented the wheel. To deal with some bad bugs caused by memory leaks I ended up with this simple solution: I made one header file that, when included, replaces the malloc/calloc/realloc/free functions with some other functions that do the actual job and insert (or remove) the pointers to...
0
9932
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11109
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5782
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5979
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4602
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.