Hi List,
This question can be categorised under "C programming in Linux", but
as I didnt find any group of that sort, I post it here.
I have a small program to print the stack trace of a particular
function. Here is the code:
=============== =============== =============== =======
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
void print_trace (void){
void *arr[20];
size_t asize, icnt;
char **str;
asize = backtrace (arr, 20);
str = backtrace_symbo ls (arr, asize);
for (icnt=0; icnt<asize; ++icnt)
printf ("%s\n",str[icnt]);
free (str);
}
int main(int argc, char **argv)
{
print_trace ();
return 0;
}
=============== =============== =============== =======
By calling backtrace ( ) and backtrace_symbo ls ( ) I can get a trace
of the calling functions path.
What I would like to know is if I can find the contents of the calling
functions () s argument values too?
More precisely:
A(void) {
....
backtrace ( )
backtrace_symbo ls ( )
....
}
B (int foo, int bar){
A () ;
....
}
C (int foo, int bar, int baz){
B ();
....
}
int main (){
C ()
....
....
}
>From the backtrace_symbo ls we can generate a path of the function call
main() calling C ()-C() calling B() -B() calling A(). Can we also
get the values for the arguments used in C (foo, bar, baz) and B (foo,
bar)? If we could then how?
Thanks
Anirbid 5 2570
On 9 Feb, 13:11, "anirbid.baner. ..@gmail.com"
<anirbid.baner. ..@gmail.comwro te:
Hi List,
This question can be categorised under "C programming in Linux", but
as I didnt find any group of that sort, I post it here.
<Off-topic>
It's actually a question about the GNU libc library, and is strictly
speaking off-topic here.
One of the GNU mailing lists might be an appropriate place to ask. http://www.gnu.org/software/libc/man...acktraces.html
seems to cover what it can do.
Accessing function arguments isn't on the list. It would be difficult
to provide in any optimised situation, I'd have thought.
</Off-topic> an************* *@gmail.com wrote:
Hi List,
This question can be categorised under "C programming in Linux", but
as I didnt find any group of that sort, I post it here.
I have a small program to print the stack trace of a particular
function. Here is the code:
=============== =============== =============== =======
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
void print_trace (void){
void *arr[20];
size_t asize, icnt;
char **str;
asize = backtrace (arr, 20);
str = backtrace_symbo ls (arr, asize);
for (icnt=0; icnt<asize; ++icnt)
printf ("%s\n",str[icnt]);
free (str);
}
int main(int argc, char **argv)
{
print_trace ();
return 0;
}
=============== =============== =============== =======
By calling backtrace ( ) and backtrace_symbo ls ( ) I can get a trace
of the calling functions path.
What I would like to know is if I can find the contents of the calling
functions () s argument values too?
More precisely:
A(void) {
...
backtrace ( )
backtrace_symbo ls ( )
...
}
B (int foo, int bar){
A () ;
...
}
C (int foo, int bar, int baz){
B ();
...
}
int main (){
C ()
...
...
}
>>From the backtrace_symbo ls we can generate a path of the function call
main() calling C ()-C() calling B() -B() calling A(). Can we also
get the values for the arguments used in C (foo, bar, baz) and B (foo,
bar)? If we could then how?
Thanks
Anirbid
Of course you can. You have just to write a debugger.
To know what the values in the stack *are* you have to know the
type of the arguments. THEN and only then, you can interpret
the bits in the stack in a meaningful fashion. If not, you can just
see some bits but you have no idea of what they represent.
Besides, you have to know that the values start at a certain offset from
the stack, the organization of stack/frame pointer, and several other
interesting things.
Writing a debugger is a lot of fun. Lcc-win32's debugger costed me some
pain, but it was worth.
It is not a completely general debugger of course. I have
never tested it outside lcc-win32, and I suppose that you have enough
time to write a differeent debugger for each compiler you will use.
Debug information formats vary a lot. Microsoft used NB09 in Windows 98
and changed to NB10 in windows 2000. I use NB09 since I did not see why
I should change.
Gcc uses a different format called "stabs", under windows, and in the
old versions of linux. Now the changed to DWARF, leaving the stabs format.
Under linux, I use the stabs format, and DWARF when there is no other
choice.
But there is also not only the debug information format that changes.
You have to know that the frame pointer organization
changes considerably if you are in optimized code or not.
This could throw off many of your offsets if you do not take care.
But it is a fun project. ma**********@po box.com wrote, On 09/02/07 13:29:
On 9 Feb, 13:11, "anirbid.baner. ..@gmail.com"
<anirbid.baner. ..@gmail.comwro te:
>Hi List,
This question can be categorised under "C programming in Linux", but as I didnt find any group of that sort, I post it here.
<Off-topic>
It's actually a question about the GNU libc library, and is strictlybe a good place to look.
speaking off-topic here.
<snip>
The linux application development groups would probably be a good place
to ask after checking the relevant FAQ of course.
--
Flash Gordon
"an************ **@gmail.com" wrote:
>
This question can be categorised under "C programming in Linux",
but as I didnt find any group of that sort, I post it here.
I have a small program to print the stack trace of a particular
function. Here is the code:
=============== =============== =============== =======
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
.... snip ...
>
From the backtrace_symbo ls we can generate a path of the function
call main() calling C ()-C() calling B() -B() calling A().
Can we also get the values for the arguments used in C (foo, bar,
baz) and B (foo, bar)? If we could then how?
First, this is not a C question. Try comp.unix.progr ammer. There
is no such thing as <execinfo.het c. in standard C.
Second, C parameters are passed by value, and may be freely
modified. Thus, even if you can see the present value of those
parameters, there is no guarantee that those are the passed-in
values.
--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
<an************ **@gmail.comwro te in message
news:11******** *************@j 27g2000cwj.goog legroups.com...
Hi List,
This question can be categorised under "C programming in Linux", but
as I didnt find any group of that sort, I post it here.
comp.unix.progr ammer would be a good start for anything POSIX. There's
also several Linux newsgroups under comp.os.linux.
From the backtrace_symbo ls we can generate a path of the function call
main() calling C ()-C() calling B() -B() calling A(). Can we also
get the values for the arguments used in C (foo, bar, baz) and B (foo,
bar)? If we could then how?
You probably can't do it, and if you can it certainly won't be portable.
There's no guarantee that the calling functions' arguments still exist,
as they may have been passed in registers (depending on the platform) or
their location on the stack may have been reused for other purposes.
You're lucky to get the function call path, and that isn't portable
either.
If you need those details, your best bet is a debugger.
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Justin |
last post by:
I have created a dataset with two tables and an insert command, I need to be
able to retreive the Key Identity after inserting into table "A" for use in
table "B".
Should I use ExecuteScalar() or is there a better solution?
Thanks, Justin.
|
by: Stu Lock |
last post by:
Hi,
I have a stored procedure:
--/ snip /--
CREATE PROCEDURE sp_AddEditUsers
(
@Users_ID int,
@UserName nvarchar(80),
@Password nvarchar(80),
|
by: Andy |
last post by:
Hi All.
I'm working for a company that has set out a guideline for retrieving
data from a database. Nobody can explain to me the reason for the
following.
When retrieving a set of records from database to a VB.net app, they
retrieve the database fields as a record set
eg. "select name, suburb from myTable"
|
by: Sakke |
last post by:
Hello!
We have written a GCryptoSvr.dll COM server in C++. Inside that resides
WebClient COM component. WebClient CLSID is
{8DC27D48-F94C-434B-A509-C3E1A3E75B9E}. When we are using that WebClient
COM component from C++ code it works just fine. However when we try to
use that same WebClient in the same machine with following C# code:
using GCRYPTOSVRLib;
WEBClient WC = new WEBClient();
|
by: Susanne Klemm |
last post by:
Hello!
I use a procedure to insert a new row into a table with an identity
column. The procedure has an output parameter which gives me the
inserted identity value. This worked well for a long time. Now the
identity value is over 700.000 and I get errors whiles retrieving the
inserted identitiy value. If I delete rows and reset the identity
everything works well again. So I think it is a data type problem.
My Procedure:
| |
by: gary.bernstein |
last post by:
I want to call a singleton getInstance function to retrieve a
templatized object without knowing what types were used to create the
singleton object in the first call to getInstance. How can I do this
non-intrusively -- I.e., without, for example, typedef'ing the types
in every compilation unit?
Background:
Our code base has assert macros that need to reboot the system after
notifying components via a single templatized Component...
|
by: Sanjay Pais |
last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time
using the with - over clauses
In query analyser, the data is retrieved in under a second.
When retrieving using the data adaptor.fill or datareader to retrieve the
data it takes over 24 seconds.
public System.Data.SqlClient.SqlDataReader List1(int PageIndex, int
PageSize, string ItemName, string UserIDs, DateTime DateStart, DateTime
DateEnd, int status,...
|
by: smartin |
last post by:
Hi,
I'm having problem retrieving data from an SQL stored procedure. I tried debugging but it wont give a the reason for the error. it just throws an exception after executing cmd.ExecuteNonQuery without any details. Can anyone please help me.. Im stuck on it since 2 days
Thanks
Stored Procedure
|
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...
|
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...
|
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...
| |
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |