473,946 Members | 15,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debug memory !

Hi !

I have a program with almost 100 sources.

The program coredump so i want debug the memory and i try memwatch but i
don't get the result i want.

The program crash so memwatch don't create the log's file. Also, memwatch
just tell you how many memory allocate et free.

If someone know some tips or program to help me, i will greatly appreciate.

In my program, i have some declaration like this : *ptr = "abcdef" and
before any malloc the program try to change de string "abcdef" to "bbcdef".
But with cc compiler this command is ok. But with gcc compiler i got a
coredump. But isn't the original coredump i want to debug. And i must use
gcc for use memwatch.

So it's very difficult to debug ... any help please !

P.S : Excuse me for my english, it's not my first language !

Thank !
Nov 14 '05 #1
2 2000
Eric Mathieu wrote:
.... snip ...
In my program, i have some declaration like this : *ptr = "abcdef"
and before any malloc the program try to change de string "abcdef"
to "bbcdef". But with cc compiler this command is ok. But with gcc
compiler i got a coredump. But isn't the original coredump i want
to debug. And i must use gcc for use memwatch.

So it's very difficult to debug ... any help please !


That declaration make ptr point to an unmodifiable string. You
would be better off declaring it as "const char *ptr =
"abcdef";". Then you will be warned about misuse if you have a
suitable set of options set for gcc, such as "-W -Wall -ansi -
pedantic". If you also add -Wwrite-strings you will also be
warned about the poor declaration.

If you truly want an initialized but modifiable string there, you
could declare:

static char foo[] = "abcdef";
char *ptr = & foo[0];

and foos size can be discovered by either:

1 + strlen(foo) /* before any modification */
or
sizeof foo /* at the declaration scope */

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #2
On Sun, 20 Jun 2004, Eric Mathieu wrote:
Hi !

I have a program with almost 100 sources.

The program coredump so i want debug the memory and i try memwatch but i
don't get the result i want.

The program crash so memwatch don't create the log's file. Also, memwatch
just tell you how many memory allocate et free.

If someone know some tips or program to help me, i will greatly appreciate.
Not really a question about the C programming language. A general trick
for debugging a crash is to insert printf statements. Run the code and
look at the output. From the printf statements you should be able to
narrow down where the crash is occurring. Keep adding an dremove printf
statements until you narrow it down to a small block of code.

Anything better than that will depend on the tools available for your
implementation. That is definitely off-topic for this newsgroup.
In my program, i have some declaration like this : *ptr = "abcdef" and
before any malloc the program try to change de string "abcdef" to "bbcdef".
But with cc compiler this command is ok. But with gcc compiler i got a
coredump. But isn't the original coredump i want to debug. And i must use
gcc for use memwatch.
Here is the bug. Just because one compiler (cc) lets you do something does
not mean it is correct. Modifying a string literal has undefined
behaviour. Don't do that. Try:

char ptr[] = "abcdef";

This is an array of char that has been initialized with the data "abcdef".
This is something that you can modify, always.
So it's very difficult to debug ... any help please !

P.S : Excuse me for my english, it's not my first language !

Thank !


--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@ whitehouse.gov
Nov 14 '05 #3

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

Similar topics

6
595
by: Cormac | last post by:
Hi everyone, I'm writing Pure Data externals in C++ using Ms Visual C++ 7.0 and Windows2000. I'm running motions sensor hardware so there's a bit of real time data processing involved. When I'm running my objects in Pure Data, I get an assertion failure after a few seconds of running the motion sensors and I can't seem to get rid of it. The error occurs in the expression _CrtCheckMemory(). Could anyone provide some possible solutions?
8
2712
by: Davy | last post by:
Hi all, I use VC and gcc/gdb to compile and debug C/C++ files. But I found some of the debug version of the compiled files are too large to be run in a small RAM. Can I compile C/C++ Debug partially? Something like: fileA.c fileB.c And I can compile fileA.c with debug info and compile fileB.c without debug info?
7
2596
by: Techno Learner | last post by:
Sorry for the lame question but, what's the difference between Debug and Release versions?
1
2091
by: spiff | last post by:
We are migrating from VC++ 6 to VC++ 2003. It is a plain, unmanaged application with both C and C++ source. When running the debug build, even outside the debugger, the memory allocation/deallocation performance appears to be orders of magnitude slower than in VC++ 6. The release build runs fine - no performance problems. We've rewritten some of the code to do fewer memory allocations/deallocations and that has helped those pieces. However,...
5
2224
by: greg.merideth | last post by:
I'm working on a service for a project that is producing some bizarre behavior. In debug mode while the service is running, the memory usage of the service (watching with process explorer) goes from 18MB to 34MB to 711+MB back down to 51MB then down to 18MB every 1-2 minutes. The service maintains a List<t,v> of 4400 objects that are being processed throughout the services life. No secondary objects are created nor released. I can...
2
2388
by: Epetruk | last post by:
Hello, I have a problem where an application I am working on throws an OutOfMemoryException when I run it in Release mode, whereas it doesn't do this when I am running in Debug. The application is developed using C++/Managed C++ and built using VS 2003 under .NET framework 1.1. In Debug, it uses of up to 600Mb of memory, whereas in Release it only gets
2
2718
by: Dave Johansen | last post by:
I just converted a solution from Visual Studio 2003 to Visual Studio 2005 and the Debug mode seems to be running just fine, but the Release mode crashes on the following code: std::ifstream in("myfile.txt"); float value; in >value; //The crash happens here in the getloc() function The above code is actually from a library built in Debug mode that is linked into the Release build of the executable. Does anyone have any
3
2429
by: Noah | last post by:
On May 6, 6:27 am, David <wizza...@gmail.comwrote: You need to use the debug build of Python to get exact numbers, but there are a few tricks you can use with the standard build to detect memory leaks. The simplest thing is to simply watch the RSS column output of `ps aux` (I'm assuming you are using UNIX). The other trick I got from Chris Siebenmann http://utcc.utoronto.ca/~cks/space/blog/python/GetAllObjects I modified his example a...
2
4097
by: =?Utf-8?B?V2lsbGlhbSBNY0lscm95?= | last post by:
Here's the problem. I've been developing a C++ application since 2003 using the default settings. Comes time to find all the memory leaks. I downloaded a nifty package that won't work unless I use the debug library DLLs. I get nothing but complaints from Visual Studio 2008. On <name-of-appProperty Page I change Use of MFC to Shared DLL. This presents a problem. I am told that the Linker is conflicted as follows: LINK : warning...
2
1390
by: Jim Rutledge | last post by:
i am gettin back into programming with visual studio 2003 and using c# to program in . I am having trouble in debug mode when i click to use the Memory 1 window .. it has completely disappeared , and i cant unhide it or find it . i can autohide memory 2 ,3 and 4 and find them all the time , so its JUST memory 1 that has disappeared .. oh and on the note of memory windows , . Seems to me that I could use a statement like this one. byte...
0
10150
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
9975
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
11552
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
11324
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
9873
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
8240
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
7403
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();...
0
6318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.