473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Memory Dump

Can someone please tell me how do I dump memory in C.
I tryed to define a void pointer to an offset but It doesn't work as I
expected. A tiny example would be very nice.

Nov 15 '05 #1
6 30269
Pacher R. Dragos a écrit :
Can someone please tell me how do I dump memory in C.
I tryed to define a void pointer to an offset but It doesn't work as I
expected. A tiny example would be very nice.

Try a pointer to unsigned char.
Nov 15 '05 #2

Emmanuel Delahaye wrote:
Try a pointer to unsigned char.


/* type ?? */ data = 0xffff;
unsigned char * offset = &data;

/* i haven't tryed this because i need a compatible type */
printf("memory at address %p is %p ", &data, *offset);

Any suggestions!

Nov 15 '05 #3
Pacher R. Dragos a écrit :
Emmanuel Delahaye wrote:
Try a pointer to unsigned char.
/* type ?? */ data = 0xffff;
unsigned char * offset = &data;


cast required. const is a good idea too...

unsigned char const * offset = (unsigned char const *) &data;
/* i haven't tryed this because i need a compatible type */
printf("memory at address %p is %p ", &data, *offset);


printf ("memory at address %p is %02X\n", &data, (unsigned) *offset);

Try that.

#include <stdio.h>

int main (void)
{
int x = 0x1234;
unsigned char const *p = (unsigned char const *) & x;

size_t i;

for (i=0; i < sizeof x; i++)
{
printf("%02X ", p[i]);
}
printf ("\n");

return 0;
}

Note that the result is implementation-dependent.

On my machine(WinTel XP/Mingw)

34 12 00 00
Nov 15 '05 #4
void dump_memory(void* data, size_t len)
{
size_t i;
printf("Data in [%p..%p): ",data,data+len);
for (i=0;i<len;i++)
printf("%02X ", ((unsigned char*)data)[i] );
printf("\n");
}
/* cutomize it to your heart's desire... */

Nov 15 '05 #5
David Lee Lambert a écrit :
void dump_memory(void* data, size_t len)


void dump_memory(void const* data, size_t len)
Nov 15 '05 #6
"David Lee Lambert" <la******@cse.msu.edu> writes:
void dump_memory(void* data, size_t len)
{
size_t i;
printf("Data in [%p..%p): ",data,data+len);
"data+len" is a constraint violation; you can't do arithmetic on void
pointers. (gcc supports this as an extension by pretending that void*
is char*).
for (i=0;i<len;i++)
printf("%02X ", ((unsigned char*)data)[i] );
printf("\n");
}
/* cutomize it to your heart's desire... */


--
Keith Thompson (The_Other_Keith) 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.
Nov 15 '05 #7

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

Similar topics

1
by: Otto Barnes | last post by:
Hello all, I have written a hashtable class that holds a dyanically allocated array of structs which holds data about a visualization model. This data is parsed via xerces from XML into this...
1
by: Julie Shi | last post by:
Hi I just installed Visual Studio.Net 2000 on my PC. When I start the application, I got a memory dump (the blue scree ). I repeadly tried it a few times, always get core dump. Could amyone tell...
9
by: Microsoft News Server | last post by:
Hi, I am currently having a problem with random, intermittent lock ups in my ASP.net application on our production server (99% CPU usage by 3 threads, indefinately). I currently use IIS Debug...
5
by: Allin Cottrell | last post by:
A. Suppose my program mallocs and populates an array of structs of a fixed size apiece. For example, something like: struct foo { int i; double x; char s; }; We want to save this work and...
1
by: Rick | last post by:
I want to have my application create a memory/stack dump for some non-fatal exceptions of my choosing. Basically I want to see the state of the variables when the exception occurred. Is this...
1
by: abhishek | last post by:
Hi group i have created a simple .pyd using which i m able call C function from python code. There are around 6 such functions. 4 of them work great. But when i try to run other two python's exe...
2
by: erfan | last post by:
Hi,comp.c: I try to learn malloc,facing a problem like this: -------- #include<unistd.h> #include<stdlib.h> #include<stdio.h> int main(void) {
1
by: vicage | last post by:
have installed the debugger tool for IIS 6.0. With the help of this tool I have taken hang dump. First I want to know is it possible to see what are objects created at heap, their number and size....
1
by: =?Utf-8?B?d29vZiE=?= | last post by:
My laptop is generating a memory dump and crashing. With some investigation It led me to believe there was a memory problem (used memtest86+). Changed hard drive, swapped the two 512mb RAMS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.