473,654 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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******@hotmai l.com
Jul 19 '05 #1
2 6887
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.progr ammer.

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
5902
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 about the memory usage. The image in the database is about 520ko.
2
3634
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 tested the pure Tkinter, # by modifiing on of the examples in the distribution. # This little guy also exibits the same behaviour. # Namely: every time the window is closed and reoppend, # there is memory leak of several hundreds 384K
4
3865
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 doesn't work ;( I wrote this code the map the content of the file in memory:     /* gets file size */     file = fopen(src, "r");     if (!file) {         return (0);
9
5539
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 shell pieces like this: <pre><code> #!/bin/sh ftp -i -n ftp.server.com&lt; &lt;EOF user username password epsv4 cd /
11
2488
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 which size is 50MB and the second 30MB. Now we come to my problem. Is there possibility to swap this rows without using system memory (preferably in Unix/Linux)? Is there any function in C to do this?
3
6701
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 occurs the following error: <b>Fatal error</b>: Allowed memory size of 188743680 bytes exhausted (tried to allocate 240 bytes) in <b>.../public_html/getimage.php</b> on line <b>x</b><br />
5
2150
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 header('Content-type: image/jpeg'); $link = mysql_connect('localhost', 'root', ''); if (!$link) {
6
1961
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 a little but I can't seem to get it to work. It attaches the file properly, but only displays the Plain Text message, even in an HTML-capable mail client. I'm guessing it has something to do with the placement of the boundaries,
7
6651
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 tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
0
8294
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
8816
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
8709
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...
1
8494
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
7309
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...
0
5627
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
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1924
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.