473,883 Members | 2,797 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 4016
CBFalconer wrote:
It's portable, under C99.
For me, "recently" long predates "C99". C99 is yesterday. I'm ancient.
Oct 2 '06 #31
CBFalconer said:
Ian Collins wrote:
>Richard Heathfield wrote:
... snip about preinitializing everything ...
>>>
I beg to differ. I mean, yes, it has the effect that you say it
has - on some compilers, anyway - but it doesn't harm the
development process at all.

Thank goodness C99 gave us the ability to declare variables at
point of use, this entire debate becomes moot.

On the contrary, to my mind this simply opens up another area in
which to foul things. In particular such declarations are
inordinately sensitive to goto to points within the block.
Not for people who avoid goto like the... the... like they avoid cliches.
Without initialization, this problem goes away.
You seem to be saying that, IF I adopt one particular coding practice that I
find unwise (the use of goto), AND if I adopt another particular coding
practice that I find unwise (the use of on-the-fly declarations), THEN a
practice that I find useful may become less useful. Well, perhaps. And IF I
start walking around with my eyes shut, AND changing my direction of motion
randomly, THEN I won't bother glancing right, left, and right again before
crossing, since there won't be any point. But until then...
I don't buy the argument that goto should never be used.
I have never tried to sell that argument, as far as I can recall. On the day
a goto makes my code clearer to me than a more structured approach, I'm
quite prepared to use it. Programming is about clarity, after all. But a
goto that dives back up above an uninitialised mixed declaration is even
less likely than usual to strike me as constituting a way of making the
code clearer.

--
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 2 '06 #32
CBFalconer said:
jmcgill wrote:
>>
int k=SOME_MAX;
for( int i=0; i<k; i++ ){/* wobble */}

I only recently realized that was a non-portable extension, even though
I've been using it since, oh, forever.

It's portable, under C99.
But C99 is itself not portable.

--
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 2 '06 #33
On Mon, 02 Oct 2006 05:04:21 +0000, Richard Heathfield
<in*****@invali d.invalidwrote:
>CBFalconer said:
>jmcgill wrote:
>>>
int k=SOME_MAX;
for( int i=0; i<k; i++ ){/* wobble */}

I only recently realized that was a non-portable extension, even though
I've been using it since, oh, forever.

It's portable, under C99.

But C99 is itself not portable.
And the reasons that support that argument make C90 (strictly) not
portable as well.

--
jay
Oct 3 '06 #34
jaysome said:
On Mon, 02 Oct 2006 05:04:21 +0000, Richard Heathfield
<in*****@invali d.invalidwrote:
>>CBFalconer said:
>>jmcgill wrote:

int k=SOME_MAX;
for( int i=0; i<k; i++ ){/* wobble */}

I only recently realized that was a non-portable extension, even though
I've been using it since, oh, forever.

It's portable, under C99.

But C99 is itself not portable.

And the reasons that support that argument make C90 (strictly) not
portable as well.
Sure - strictly speaking. But in practice, I can write normal C90 code -
stuff that doesn't mess around in the dark cobwebby corners of the language
- and expect it to compile just about anywhere. But just about any single
C99 feature I choose to employ could render my code non-portable. Even //
comments will cause my code to be rejected by some implementations
(including the one I use most often myself).

Almost all of the code I write nowadays falls into one of four categories:

1) I know it's for S16ILP32 Linux
2) I know it's for S16ILP32 Windows
3) I know it's for both 1) and 2) above
4) I haven't the faintest idea what it will end up on

And most tends to be in the last category. So I have to choose - what do I
consider to be the *most portable* way to write code? And as far as I can
make out, the most portable strategy is to write code in the common subset
of C90 and C99. If anyone has any better ideas, I'd love to hear them.

--
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 3 '06 #35
Frederick Gotham <fg*******@SPAM .comwrote:
Richard Heathfield posted:
ac*********@gma il.com said:
The application/software that is being run, is messing up the memory
due to which a subsequent malloc fails.
Check every malloc/calloc/realloc to ensure it succeeded before you rely
on its return value.

If malloc'ing less than a kilobyte, I wouldn't bother.
On a board which doesn't have the memory to run gdb? You'd better.

Richard
Oct 3 '06 #36
jacob navia <ja***@jacob.re mcomp.frwrote:
Frederick Gotham wrote:
Richard Heathfield posted:
>Check every malloc/calloc/realloc to ensure it succeeded before you rely
on its return value.
If malloc'ing less than a kilobyte, I wouldn't bother.

In a debug setting is better to never check malloc, so, if there is any
failure the program crashes immediately at the point of failure.
Assuming that writing through a null pointer - on an unusual kind of
board, no less - _will always immediately_ crash is unbelievably stupid.
>Set indeterminate ('dangling') pointers to NULL.

This is good advice. Start with KNOWN conditions.
It is bad advice. It makes you rely on the assumption that you have
determined all such pointers.

Richard
Oct 3 '06 #37
Richard Bos said:
jacob navia <ja***@jacob.re mcomp.frwrote:
>Frederick Gotham wrote:
Richard Heathfield posted:

Check every malloc/calloc/realloc to ensure it succeeded before you
rely on its return value.

If malloc'ing less than a kilobyte, I wouldn't bother.

In a debug setting is better to never check malloc, so, if there is any
failure the program crashes immediately at the point of failure.

Assuming that writing through a null pointer - on an unusual kind of
board, no less - _will always immediately_ crash is unbelievably stupid.
The latest party line appears to be that Mr Navia isn't unbelievably stupid,
but merely not very skilled at English. It may be that he intended to say
"Whether or not in a debug setting, it is better always to check malloc;
there is no guarantee that the program will crash immediately at the point
of failure" but that he accidentally said pretty much the exact opposite.

>>Set indeterminate ('dangling') pointers to NULL.

This is good advice. Start with KNOWN conditions.

It is bad advice. It makes you rely on the assumption that you have
determined all such pointers.
No, it isn't bad advice, and no, it doesn't make you rely on any such thing.
It merely increases your confidence that your program's behaviour is
deterministic, and makes debugging a lot easier.

--
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 3 '06 #38
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.frwrote:

>>Frederick Gotham wrote:
>>>Richard Heathfield posted:
Check every malloc/calloc/realloc to ensure it succeeded before you rely
on its return value.

If malloc'ing less than a kilobyte, I wouldn't bother.

In a debug setting is better to never check malloc, so, if there is any
failure the program crashes immediately at the point of failure.


Assuming that writing through a null pointer - on an unusual kind of
board, no less - _will always immediately_ crash is unbelievably stupid.
The OP is running linux. Linux has memory protection, as far
as I remember.

But better treat people of stupid immediately, specially if
its Jacob Navia...

That doesn't cost anything since the guy never gets upset...
Oct 3 '06 #39
Richard Heathfield wrote:
Richard Bos said:

>>jacob navia <ja***@jacob.re mcomp.frwrote:

>>>Frederick Gotham wrote:

Richard Heathfield posted:
>Check every malloc/calloc/realloc to ensure it succeeded before you
>rely on its return value.

If malloc'ing less than a kilobyte, I wouldn't bother.

In a debug setting is better to never check malloc, so, if there is any
failure the program crashes immediately at the point of failure.

Assuming that writing through a null pointer - on an unusual kind of
board, no less - _will always immediately_ crash is unbelievably stupid.


The latest party line appears to be that Mr Navia isn't unbelievably stupid,
but merely not very skilled at English. It may be that he intended to say
"Whether or not in a debug setting, it is better always to check malloc;
there is no guarantee that the program will crash immediately at the point
of failure" but that he accidentally said pretty much the exact opposite.
Linux supposes memory protection as far as I remember.
The OP said it was running some linux system!

jacob
Oct 3 '06 #40

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

Similar topics

7
4945
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
7071
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
2523
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
4896
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
7806
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
9944
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
11154
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
10762
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...
0
10422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7977
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5807
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...
2
4228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3241
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.