473,414 Members | 1,989 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,414 software developers and data experts.

displaying memory content in LINUX

I want to display memory content using C++ on LINUX. For example, the
user may ask to display 256 bytes from 0x1000ff00. The problem is , if
any location is invalid, the program will coredump because of attempt
to access invalid memory.I understand that in Windows OS there is a
function that tells if a memory location is valid or invalid. Is there
a similar function in Linux? How does gdb display memory content?
I will appreciate a response.

Shyamal Pain
sp******@hotmail.com
Jul 19 '05 #1
2 6868
shyamal wrote:
I want to display memory content using C++ on LINUX. For example, the
user may ask to display 256 bytes from 0x1000ff00. The problem is , if
any location is invalid, the program will coredump because of attempt
to access invalid memory.I understand that in Windows OS there is a
function that tells if a memory location is valid or invalid. Is there
a similar function in Linux? How does gdb display memory content?
I will appreciate a response.


This is off topic here - try comp.unix.programmer.

Hint - any system calls you sent an invalid address to do not abort,
they will return an error code. Try "write()-ing" the memory range to a
pipe and read it back. Or simply catch the SIGSEGV signal and throw an
exception when the signal handler is caught - however you will need to
make sure you use -fnon-call-exceptions in when compiling your code.
Here is an example using signals.

#include <iostream>

#include <signal.h>
void SegFaultAction( int , siginfo_t *, void * );
void SetupSignal()
{

struct sigaction a_sig[1] = { { 0 } };
struct sigaction a_old_sig[1] = { { 0 } };

a_sig->sa_sigaction = SegFaultAction;
a_sig->sa_flags = SA_SIGINFO | SA_NOMASK;

if ( -1 == sigaction( SIGSEGV, a_sig, a_old_sig ) )
{
throw "Failed to set handler";
}

}
void SegFaultAction( int i_num, siginfo_t * i_info, void * i_val )
{
const siginfo_t & v = * i_info;

std::cout << v.si_signo << "= Signal number\n";
std::cout << v.si_errno << "= An errno value\n";
std::cout << v.si_code << "= Signal code\n";
std::cout << v.si_pid << "= Sending process ID\n";
std::cout << v.si_uid << "= Real user ID of sending process\n";
std::cout << v.si_status << "= Exit value or signal\n";
std::cout << v.si_utime << "= User time consumed\n";
std::cout << v.si_stime << "= System time consumed\n";
// std::cout << (int) v.si_value << "= Signal value\n";
std::cout << v.si_int << "= POSIX.1b signal\n";
std::cout << v.si_ptr << "= POSIX.1b signal\n";
std::cout << v.si_addr << "= Memory location which caused fault\n";
std::cout << v.si_band << "= Band event\n";
std::cout << v.si_fd << "= File descriptor\n";

// throw "HELP";
throw * i_info;
}

char * foo = (char*) 0xdeadbeef;

int main()
{
SetupSignal();

try
{

* foo = 1;
}
catch ( const siginfo_t & v )
{
// caught a signal

std::cout << v.si_signo << "= Signal number\n";
std::cout << v.si_errno << "= An errno value\n";
std::cout << v.si_code << "= Signal code\n";
std::cout << v.si_pid << "= Sending process ID\n";
std::cout << v.si_uid << "= Real user ID of sending process\n";
std::cout << v.si_status << "= Exit value or signal\n";
std::cout << v.si_utime << "= User time consumed\n";
std::cout << v.si_stime << "= System time consumed\n";
// std::cout << (int) v.si_value << "= Signal value\n";
std::cout << v.si_int << "= POSIX.1b signal\n";
std::cout << v.si_ptr << "= POSIX.1b signal\n";
std::cout << v.si_addr << "= Memory location which caused fault\n";
std::cout << v.si_band << "= Band event\n";
std::cout << v.si_fd << "= File descriptor\n";
}
catch ( ... )
{
std::cout << "caught somthing else\n";
}

}

Jul 19 '05 #2
shyamal wrote:
I want to display memory content using C++ on LINUX. For example, the


You are aware of the fact that you cannot display memory contents from
arbitrary locations, aren't you? Or at least, the contents you find at
location 0x1000000 is not really located there, since each process has its
own adress space.

Jul 19 '05 #3

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

Similar topics

3
by: Matthieu MARC | last post by:
Hi everybody, I'm writting a script which take image data from mysql (blob) and draw the image to screen. At the end of the message you will find my php code. I put lots of numbered message...
2
by: Elbert Lev | last post by:
#When I'm running this script on my windows NT4.0 box, #every time dialog box is reopened there is memory growth 384K. #Bellow is the text I sent to Stephen Ferg (author of easygui) # I have...
4
by: Slaanesh | last post by:
Hi, I have to uncompress a buffer extracted from a file (not the entire file is compressed, it begins after the 8th byte). The data has been compressed using zlib library. My problem is that it...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
11
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer...
3
by: f.amann | last post by:
hi there! i save images in a mysql db and i wrote a script called getimage.php to display them. in my getimage.php i want to resize my images to display them as thumbnails but there always...
5
by: ljuljacka | last post by:
I'm trying to display resized images. Locations of images are fetched from database. The problem is that with the following code, I get only the first image displayed: <?php...
6
by: Karl Groves | last post by:
I'm trying to work out a mail system which can send an attachment as well as an HTML formatted message (and a default plain text version). I found some pretty good code on PHP.net and modified it...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
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...
0
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...
0
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...
0
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...

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.