Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?): (19 Items)
   
View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Hi,

I'm debugging a memory issue on an mpc8313 board.
For this, I'd like to view a specifiy portion of memory. I select the approriate variable in the "Variables" window in 
the Debugger View of Momentics, choose "View Memory"... The Memory window opens, but says "Target Rquest failed: Unable 
to read memory."

I have done some research, I think a quick fix might be to disable gdb memory access checking ("set mem inaccessible-by-
default off"). But where can I specify this? The debugging window settings specify file ".gdbinit", but this file is 
found nowhere on my system.

Or am I completely on the wrong track here?

Help greatly appreciated!

Greetings,
 Marc
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Marc Roessler wrote:
> Hi,
> 
> I'm debugging a memory issue on an mpc8313 board.
> For this, I'd like to view a specifiy portion of memory. I select the approriate variable in the "Variables" window in
 the Debugger View of Momentics, choose "View Memory"... The Memory window opens, but says "Target Rquest failed: Unable
 to read memory."
> 
> I have done some research, I think a quick fix might be to disable gdb memory access checking ("set mem inaccessible-
by-default off"). But where can I specify this? The debugging window settings specify file ".gdbinit", but this file is 
found nowhere on my system.

You can create the file.


Have you tried to specify this command in your gdb console? 
That would be "quick" way to check if you are right.


Thanks,

Aleksandar Ristovski




Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
You have to create the ".gdbinit" file and add your customized gdb 
command. You have to point to it in the debug launch config settings.

Marc Roessler wrote:
> Hi,
>
> I'm debugging a memory issue on an mpc8313 board.
> For this, I'd like to view a specifiy portion of memory. I select the approriate variable in the "Variables" window in
 the Debugger View of Momentics, choose "View Memory"... The Memory window opens, but says "Target Rquest failed: Unable
 to read memory."
>
> I have done some research, I think a quick fix might be to disable gdb memory access checking ("set mem inaccessible-
by-default off"). But where can I specify this? The debugging window settings specify file ".gdbinit", but this file is 
found nowhere on my system.
>
> Or am I completely on the wrong track here?
>
> Help greatly appreciated!
>
> Greetings,
>  Marc
>
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post32042
>
>   
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
You can do all gdb commands from gdb console which is available from console drop down or when you click on gdb target 
in the Debug view.

However this specific problem can be cause by IDE reading memory beyond the proper region. To check if it is that case 
open Table Renderings  preferences
from Memory view menu (triangle button) and make sure it is set to Manual

Marc Roessler wrote:
> Hi,
> 
> I'm debugging a memory issue on an mpc8313 board.
> For this, I'd like to view a specifiy portion of memory. I select the approriate variable in the "Variables" window in
 the Debugger View of Momentics, choose "View Memory"... The Memory window opens, but says "Target Rquest failed: Unable
 to read memory."
> 
> I have done some research, I think a quick fix might be to disable gdb memory access checking ("set mem inaccessible-
by-default off"). But where can I specify this? The debugging window settings specify file ".gdbinit", but this file is 
found nowhere on my system.
> 
> Or am I completely on the wrong track here?
> 
> Help greatly appreciated!
> 
> Greetings,
>  Marc
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post32042
> 
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
I set it to "manual" and it worked. Thanks!

Will the memory view show (and mark colored) also when the memory is not explicityly modified by accessing variables, 
but rather by error, such as memory management errors? (misused memcpy, misused maloc/free etc...)

Thanks, Marc
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Hmm..

Background: some part of my program is overwriting its own memory...
After running for some time, it crashes in _resmgr_io_func(), probably while trying to access my resmgr_io_funcs_t 
registered functions...

So now I need to set a "watchpoint" to some portion of memory. A normal watchpoint probably won't suffice (?) because 
this watches variables being modified, not memory. As the memory is corrupted accidentally (e.g. using memcpy or 
whatever...) i need to watch memory directly.

Is there any way to do this?

I had two ideas but don't know whether any of these is feasible:

1. Cause a physical exception when trying to write to a certain memory region. The idea is similar to guard pages 
commonly used for growing the stack or for detecting buffer overflow attacks (mark page as non-executable). The question
 is whether granularity is fine enough, and whether this works without modifying the memory layout of the program.... 
remember, changing the memory layout will change the location of the crash, thus rendering the previous choice of the 
watched memory location worthless...

2. gdb can step through code, even when it doesn't know it's source code equivalent (because it works on an asm level). 
So gdb can in principle step through the whole program. So what could in theory be done is to make gdb step through the 
program instruction by instruction, each time comparing the specified memory location with the specified value. When it 
changes, the script stops with gdb in step mode. Now the user can see where the access happened. This can take _very_ 
long to execute, as the control runs on the host. But it should be able to find the accesses automatically.

What do you think?

Greetings,
 Marc
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Marc Roessler wrote:
> Hmm..
> 
> Background: some part of my program is overwriting its own memory...
> After running for some time, it crashes in _resmgr_io_func(), probably while trying to access my resmgr_io_funcs_t 
registered functions...
> 
> So now I need to set a "watchpoint" to some portion of memory. A normal watchpoint probably won't suffice (?) because 
this watches variables being modified, not memory. As the memory is corrupted accidentally (e.g. using memcpy or 
whatever...) i need to watch memory directly.

Actually "normal" watchpoint is the same as the other 
("abnormal"?) and it monitors change in a memory location.

Depending on the underlying hardware (and our support) it 
can use hardware or software watchpoint. Software watchpoint 
may (and usually does) cause program run very slow. Hardware 
watchpoints work great.

When you set a watchpoint in gdb using symbol name, gdb 
looks up its symbol tables to figure out actual address and 
sets a watchpoint.

> 
> Is there any way to do this?
> 
> I had two ideas but don't know whether any of these is feasible:
> 
> 1. Cause a physical exception when trying to write to a certain memory region. The idea is similar to guard pages 
commonly used for growing the stack or for detecting buffer overflow attacks (mark page as non-executable). The question
 is whether granularity is fine enough, and whether this works without modifying the memory layout of the program.... 
remember, changing the memory layout will change the location of the crash, thus rendering the previous choice of the 
watched memory location worthless...

Effectively, hardware watchpoint does that. (facility must 
be present in the CPU and we must have support for it; both 
are true in case of intel cpus). Support for hardware 
watchpoint varies across other architectures.

> 
> 2. gdb can step through code, even when it doesn't know it's source code equivalent (because it works on an asm level)
. So gdb can in principle step through the whole program. So what could in theory be done is to make gdb step through 
the program instruction by instruction, each time comparing the specified memory location with the specified value. When
 it changes, the script stops with gdb in step mode. Now the user can see where the access happened. This can take 
_very_ long to execute, as the control runs on the host. But it should be able to find the accesses automatically.

That would be software watchpoint. And this 
instruction-by-instruction execution is what makes your 
program run very slowly in this mode.



To you as the user, type of watchpoint will be transparent. 
Or semi-transparent since software watchpoint has quite 
visible effects on speed of execution.



Relevant setting in gdb is :

(gdb) set can-use-hw-watchpoints 1

You almost always want to set to "1" (which is also default 
setting).  Only if this, for whatever reason, doesn't work 
(like certain architectures and some older gdbs) you should 
set it to 0 to make gdb request software watchpoint.

Note that can-use-hw-watchpoints does not guarantee that you 
will really get a hw watchpoint, but gdb will request it first.




Hope this helps,

Aleksandar
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
If you think you overriding heap memory (vs stack or static) you can use Qnx Memory Analysis tool which would trigger 
violation of this sort automatically.
Also if you use 6.4.0 or later with latest gcc you can use "Mudflap" instrumentation which can catch different types of 
memory overflow including stack and
static. If you interested please read corresponding documentation of IDE.

Marc Roessler wrote:
> Hmm..
> 
> Background: some part of my program is overwriting its own memory...
> After running for some time, it crashes in _resmgr_io_func(), probably while trying to access my resmgr_io_funcs_t 
registered functions...
> 
> So now I need to set a "watchpoint" to some portion of memory. A normal watchpoint probably won't suffice (?) because 
this watches variables being modified, not memory. As the memory is corrupted accidentally (e.g. using memcpy or 
whatever...) i need to watch memory directly.
> 
> Is there any way to do this?
> 
> I had two ideas but don't know whether any of these is feasible:
> 
> 1. Cause a physical exception when trying to write to a certain memory region. The idea is similar to guard pages 
commonly used for growing the stack or for detecting buffer overflow attacks (mark page as non-executable). The question
 is whether granularity is fine enough, and whether this works without modifying the memory layout of the program.... 
remember, changing the memory layout will change the location of the crash, thus rendering the previous choice of the 
watched memory location worthless...
> 
> 2. gdb can step through code, even when it doesn't know it's source code equivalent (because it works on an asm level)
. So gdb can in principle step through the whole program. So what could in theory be done is to make gdb step through 
the program instruction by instruction, each time comparing the specified memory location with the specified value. When
 it changes, the script stops with gdb in step mode. Now the user can see where the access happened. This can take 
_very_ long to execute, as the control runs on the host. But it should be able to find the accesses automatically.
> 
> What do you think?
> 
> Greetings,
>  Marc
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post32094
> 
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Aleksandar and Elena, thanks!

I thought a watchpoint only monitored direct accesses to a variable (i.e. on a C syntactic level)... but it seems all I 
wished for is already in place, as you described it :)

My problem turned out to be that structs were placed on the stack of a function/thread that called thread_pool_start() 
with parameter POOL_FLAG_USE_SELF. The thread pool referred to those structs. Eventually, that thread quits and the 
stack is destroyed, with dangling references.

Interestingly enough, mudflap did not discover this. Neither did it find a previous error where I misused memcpy() 
(copied too much data).

Seems there is no substitute to careful programming and a good architectur from ground up. Well maybe the watchpoints 
will help a bit next time :)

Thanks,
 Marc
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
I've fixed my problem, but I'd still like to be able to use watchpoints for the next time, so I experimented a bit. I've
 tried with a small program, but haven't been able to actually use watchpoints on memory...

My Program (for PPC):

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
    char b[4];
    char a[4];    
    int i;
    
    for(i=0;i<200;i++) {
        b[i] = 'x';
    }

    return EXIT_SUCCESS;
}

This program starts to write in b, eventually overwrites a, then crashes (as intended).
By stepping through the program I verified that a is overwritten.

I can set a watchpoint to "a" ("Add Watchpoint C/C++", expression "a") but this isn't ever triggered.
Same if I set the watchpoint in the memory view (this time on the memory address directly).

I noticed that gdb says "Changing watchpoint type to software and trying again." on the console, then exits.

When I force gdb to sw watchpoints, it _seems_ to work, but when the code finally stops, the thread label in the debug 
window says "Suspended: Watchpoint is out of scope").

Any suggestions?

Greetings,
 Marc
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  

Marc Roessler wrote:
> I've fixed my problem, but I'd still like to be able to use watchpoints for the next time, so I experimented a bit. 
I've tried with a small program, but haven't been able to actually use watchpoints on memory...
> 
> My Program (for PPC):
> 
> #include <stdlib.h>
> #include <stdio.h>
> int main(int argc, char *argv[]) {
>     char b[4];
>     char a[4];    
>     int i;
>     
>     for(i=0;i<200;i++) {
>         b[i] = 'x';
>     }
> 
>     return EXIT_SUCCESS;
> }
> 
> This program starts to write in b, eventually overwrites a, then crashes (as intended).
> By stepping through the program I verified that a is overwritten.
> 
> I can set a watchpoint to "a" ("Add Watchpoint C/C++", expression "a") but this isn't ever triggered.
> Same if I set the watchpoint in the memory view (this time on the memory address directly).
> 
> I noticed that gdb says "Changing watchpoint type to software and trying again." on the console, then exits.


There is an issue with gdb not being able to set watchpoint 
before your run the program. There is a PR on that.

Try this:

Start your program; when it's stopped at main, set your 
watchpoint.

Continue.

That should work, whether software or hardware watchpoint is 
used.

---
Aleksandar

> 
> When I force gdb to sw watchpoints, it _seems_ to work, but when the code finally stops, the thread label in the debug
 window says "Suspended: Watchpoint is out of scope").
> 
> Any suggestions?
> 
> Greetings,
>  Marc
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post32130
> 

Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Aleksandar, that's what i did (using the GUI)... start debugging, when prog is stopped at main add watchpoint expression
 (tried with "*a@4"), continue running.. crash..
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Marc Roessler wrote:
> Aleksandar, that's what i did (using the GUI)... start debugging, when prog is stopped at main add watchpoint 
expression (tried with "*a@4"), continue running.. crash..

Could you post output from

(gdb) show version



Thanks,

Aleksandar
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
says "GNU gdb 6.8 qnx-nto (rev. 347)"
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Hello Marc,

I tried your example and I can confirm that this doesn't 
work as expected - I didn't see any errors in what you did, 
your expectations were correct and it was supposed to work.

I will open a PR for this.


Thanks,

Aleksandar
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Thanks!
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Marc Roessler wrote:
> Thanks!
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post32241
> 

Hello Marc,

Could you try attached gdb? (it is unofficial, it contains 
bug-fix for this problem but may also include some 
work-in-progress changes).

Also attached is your, slightly modified, example 
(wptest.c). There seems to be something more to it then gdb 
bug.

Compile the example twice:

1. ntoppc-gcc -g3 -O0 wptest.c -o wptest1
2. ntoppc-gcc -g3 -O0 -DVOLATILE=volatile wptest.c wptest2

wptest1 will not trigger the watchpoint. wptest2 will.


Let me know if it gives you the same results.

Thanks,

Aleksandar
Attachment: Text wptest.c 649 bytes Compressed file ntoppc-gdb.zip 1.16 MB
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Hi,

I've tested it with the gdb you supplied (renamed the old gdb, dropped the replacement gdb to the \host\win32\x86\usr\
bin directory) - doesn't seem to work.

I set watchpoints to the two boundaries, and to the 3rd element (starting counting at 0) of the character array 'a'... 
none of them is triggered.

Greetings,
 Marc
Re: View Memory: "Target Rquest failed, Unable to read memory" (gdb issue?)  
Marc Roessler wrote:
> Hi,
> 
> I've tested it with the gdb you supplied (renamed the old gdb, dropped the replacement gdb to the \host\win32\x86\usr\
bin directory) - doesn't seem to work.
> 
> I set watchpoints to the two boundaries, and to the 3rd element (starting counting at 0) of the character array 'a'...
 none of them is triggered.
> 
> Greetings,
>  Marc
> 


That is interesting. This is what I get:

Note that you need to compile the example using
ntoppc-gcc -g3 -O0 -DVOLATILE=volatile wptest.c -o wptestppc


C:\Public>ntoppc-gdb --nx wptestppc
GNU gdb 6.8 qnx-nto UNOFFICIAL
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>;
This is free software: you are free to change and 
redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type 
"show copying"
and "show warranty" for details.
This GDB was configured as "--host=i386-mingw32msvc 
--target=powerpc-unknown-nto
-qnx6.4.0"...
(gdb) target qnx tppcbe:8000
Remote debugging using tppcbe:8000
MsgNak received - resending
Remote target is big-endian
(gdb) upload wptestppc /tmp/wptestppc
(gdb) start
Temporary breakpoint 1 at 0x48040878: file wptest.c, line 10.
Starting program: C:\Public/wptestppc
Remote: /tmp/wptestppc
[New pid 630804 tid 1]

Temporary breakpoint 1, main (argc=1, argv=0x4803ff04) at 
wptest.c:10
10        VOLATILE int  boundary_1 = 0;
(gdb) watch boundary_2
Hardware watchpoint 2: boundary_2
(gdb) watch a[3]
Hardware watchpoint 3: a[3]
(gdb) c
Continuing.
Changing watchpoint type to software and trying again.
Changing watchpoint type to software and trying again.
Watchpoint 2: boundary_2

Old value = 1208221376
New value = 0
main (argc=1, argv=0x4803ff04) at wptest.c:14
14        for(i=0;i<200;i++) {
(gdb) c
Continuing.
Watchpoint 3: a[3]

Old value = 0 '\0'
New value = 120 'x'
main (argc=1, argv=0x4803ff04) at wptest.c:16
16          if (boundary_1 != 0) {
(gdb) c
Continuing.
Watchpoint 2: boundary_2

Old value = 0
New value = 2013265920
main (argc=1, argv=0x4803ff04) at wptest.c:16
16          if (boundary_1 != 0) {
(gdb) c
Continuing.

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.

Watchpoint 3 deleted because the program has left the block in
which its expression is valid.
0xfe37d934 in ?? () from 
C:/QNX641M6/target/qnx6/ppcbe/lib/libc.so.3
(gdb)


Thanks,

Aleksandar