QNX RTOS v4 Knowledge Base
QNX RTOS v4 Knowledge Base
Title |
How to find the address of the last instruction executed before entering the Slib32 on QNX4? |
Ref. No. |
QNX.000010240 |
Category(ies) |
Utilities, Development |
Issue |
Is there a way to find the entry point from a user application into a function in Slib32 if a SIGSEGV occurs while in a shared function?
|
Solution |
When a program SIGSEGVs in a Slib32 function, there is no availability to get a stack trace ("Code/Calls") from wd. The reason is that Slib32 is not compiled with the 'generate traceable stackframes' option. Also, Slib32 involves a few far calls which may cause wd problems. The following is a sample program that can be used as a test case.
------------------------------------------------------------------------
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h>
int f(int fd, struct stat *buf) { if (fd != -1) return fstat(fd, buf); else return -1; }
void main() { int filedes, rc; struct stat *buf = NULL;
filedes = open("fs.c", O_RDONLY); if (filedes != -1) { rc = f(filedes, buf); if (rc != -1) printf("File size = %dn", buf->st_size); close(filedes); } }
------------------------------------------------------------------------
This program obviously causes a SIGSEGV while executing fstat(). Here are the steps necessary to find the entry point: 1) Compile the program with the debug option: "cc -g2 -o problem problem.c". 2) Open the program with wd: "wd problem". 3) Run the program with F5 or select Go from Run menu. At this point there should be an access violation error, click OK button. 4) Open a 'Stack window', from Data menu choose Stack. Maximize the 'Stack window' with the trangle pointing up. 5) The code segment of your program is '4+privity', usually 7. Look in the 'Stack window' for the first occurance of '00000007' value(it should be found at 00009D9C). The next address in the stack '0009D98' should have a '0000A03E' value. 6) Subtract 5 from that value, would result in '0000A039', which should be the first address that called 'fstat'. 7) Close the 'Stack window' (double click on the square icon). 8) Change the module to the source, in 'Modules window' double click on [S]problem. 9) Change the code to assembly, from Code menu click on Assembly. 10) Go down till '0000A039' address is found. This address called fstat. |
|