473,883 Members | 1,663 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 4015
jacob navia said:
Richard Bos wrote:
>jacob navia <ja***@jacob.re mcomp.frwrote:
<snip>
>>>
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.
That is irrelevant in comp.lang.c - even if the OP is running Linux, that
doesn't necessarily mean that Linux is the only system on which his code
will be run. Advice given here about C should be /general/ advice; it
should be good for /any/ hosted implementation (and, if applicable, on
freestanding implementations ).

--
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 #41
jacob navia said:

<snip>
Linux supposes memory protection as far as I remember.
What has that to do with C?
The OP said it was running some linux system!
So what? If that's relevant, he's in the wrong newsgroup.

--
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 #42
jacob navia wrote:
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.
You know, it's comp.lang.c -- you either give off-topic advice (when
qualifying it as Linux only answer) or not entirely correct advice.
Even though your statement may be correct for Linux and also for many
hosted environments, I'd still rather not follow it.

But better treat people of stupid immediately, specially if
its Jacob Navia...
There are two sides to something like that.

You often get into heated discussions and present your positions
in a rather unfavourable and unfortunate way. I am glad that people
like you, Paul Hsieh, and Chris Hills participate because you are
clearly intelligent and the positions you represent are decidedly
off the group's mainstream -- this inspires thought. As always in
comp.lang.c, there are issues with the given representation and
its interpretation :-)

That doesn't cost anything since the guy never gets upset...
:-/
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Oct 3 '06 #43
Richard Heathfield wrote:
jacob navia said:

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

<snip>
>>>>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.


That is irrelevant in comp.lang.c - even if the OP is running Linux, that
doesn't necessarily mean that Linux is the only system on which his code
will be run. Advice given here about C should be /general/ advice; it
should be good for /any/ hosted implementation (and, if applicable, on
freestanding implementations ).
Who are YOU to tell ME what advice should I give?

I give advice adapted to the OP question!

He is running linux, then I assume memory protection!
Who cares about each possible CPU in the planet?
He is in a certain situation, and give specific advice to THAT
situation!

Oct 3 '06 #44
jacob navia said:
Richard Heathfield wrote:
>jacob navia said:
<snip>
>>>The OP is running linux. Linux has memory protection, as far
as I remember.


That is irrelevant in comp.lang.c - even if the OP is running Linux, that
doesn't necessarily mean that Linux is the only system on which his code
will be run. Advice given here about C should be /general/ advice; it
should be good for /any/ hosted implementation (and, if applicable, on
freestanding implementations ).

Who are YOU to tell ME what advice should I give?
I'm a guy who subscribes to comp.lang.c, which is for discussions about C,
not for discussions about Linux. That's why it says "c", not "linux", in
the group's name. Who are YOU arbitrarily to CHANGE the topic of discussion
of an INTERNATIONAL NEWSGROUP to suit YOUR whim?
I give advice adapted to the OP question!
Yes, and if you give advice that has absolutely nothing to do with C, then
nobody can stop you doing that, but on the other hand you can't stop other
people complaining about it either. Newsgroups have topics for the
excellent reason that, if they didn't, there'd just be the one newsgroup,
with 10,000,000 posts an hour, on every subject from aardvarks to zymurgy,
and nobody would be able to find anything they were interested in
discussing because everything would be all mixed in together.

I would expect to have to explain this to a Usenet newbie, but you've been
posting to Usenet for longer than I have. You should have worked it out by
now! Are you being deliberately stupid, or just accidentally stupid? It
must be one or the other - you cannot reasonably claim ignorance of
topicality after over a decade of posting to Usenet!
He is running linux, then I assume memory protection!
If Linux is relevant to his question, he's in the wrong group.
Who cares about each possible CPU in the planet?
C programmers.
He is in a certain situation, and give specific advice to THAT
situation!
The best advice you can give him is to ask his question in a newsgroup where
it's topical.

--
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 #45
Frederick Gotham <fg*******@SPAM .comwrites:
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.
That is extraordinarily bad advice.

(Frederick, I'm still waiting for your apology.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 3 '06 #46
In article <45************ ***********@new s.orange.fr>,
jacob navia <ja***@jacob.re mcomp.frwrote:
>The OP is running linux. Linux has memory protection, as far
as I remember.
Does Linux promise memory protection on every implementation?
If a system that Linux is ported to cannot do the kind of memory
protection you are thinking of, then is it prohibitted from calling
itself Linux? ucLinux has been ported to a number of embedded
environments: is it Linux on those environments or is it not?

Does Linux promise that the kind of memory protection you are thinking
of is active on -every- page of memory? What if there happens to be
writable memory within the first "page" of process memory?
SGI IRIX "has memory protection" too, but on IRIX 6.4 and later on
"big" systems that run with 16 Kb virtual pages, virtual address 0 is
*not* write protected for reasons having to do with the graphics
subsystems (which were designed to expect memory at the 8 Kb mark
so that the smallest address format could be used, for speed; that
design was done at a time when IRIX only supported 4 Kb virtual pages.)
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Oct 3 '06 #47
Walter Roberson wrote:
In article <45************ ***********@new s.orange.fr>,
jacob navia <ja***@jacob.re mcomp.frwrote:

>>The OP is running linux. Linux has memory protection, as far
as I remember.


Does Linux promise memory protection on every implementation?
If a system that Linux is ported to cannot do the kind of memory
protection you are thinking of, then is it prohibitted from calling
itself Linux? ucLinux has been ported to a number of embedded
environments: is it Linux on those environments or is it not?

Does Linux promise that the kind of memory protection you are thinking
of is active on -every- page of memory? What if there happens to be
writable memory within the first "page" of process memory?
SGI IRIX "has memory protection" too, but on IRIX 6.4 and later on
"big" systems that run with 16 Kb virtual pages, virtual address 0 is
*not* write protected for reasons having to do with the graphics
subsystems (which were designed to expect memory at the 8 Kb mark
so that the smallest address format could be used, for speed; that
design was done at a time when IRIX only supported 4 Kb virtual pages.)
The OP said:

"I am working on MontaVista Linux on a PPC board"

The PowerPC is a very modern chip with memory protection.
Linux with PPC chip is surely a combination where any NULL
access will crash, as it does in the x86 and in most
modern OSes/chips combinations.

There can be exceptions, of course, but they are that: exceptions,
and obviously you have to check for NULL in those implementations .

Oct 3 '06 #48
Keith Thompson posted:
>If malloc'ing less than a kilobyte, I wouldn't bother.

That is extraordinarily bad advice.
Of course, it depends on the requirements of the project and so forth, but
there are many circumstances in which I'd just assume that malloc succeeds.
At the very most, I might do something like:

#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:

#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);

char *const retval=ExitiveM alloc(len+1), *p=retval;

strncpy(retval, arg,len);

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

return (void)assert_du mmy, retval;
}

(I'm not entirely sure if I violate a sequence point with the "*p++ = ").

--

Frederick Gotham
Oct 3 '06 #49
Frederick Gotham said:
Keith Thompson posted:
>>If malloc'ing less than a kilobyte, I wouldn't bother.

That is extraordinarily bad advice.

Of course, it depends on the requirements of the project and so forth, but
there are many circumstances in which I'd just assume that malloc
succeeds.
It's still a stupid assumption, no matter how many times you make it.
At the very most, I might do something like:

#include <stddef.h>
#include <stdlib.h>

void *ExitiveMalloc( size_t const size)
{
void *const p = malloc(size);

if(!p) exit(EXIT_FAILU RE);
Bye-bye user's data. Who cares?
>
return p;
}
Here's an example of where I'd be wreckless with malloc:
We have no shortage of examples of stupid code. Why add to the mess? And
your code is far from wreckless. Spelling flames for the sake of it are
lame, but the difference in meaning between "reckless" and "wreckless" is
significant.

--
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 #50

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
9933
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
11121
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...
1
10836
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
10407
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
9564
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
7960
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
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4210
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
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.