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

how to set watchpoint in Workshop for C++

Hi,
I am using Workshop in Forte Development 6 on Solaris as my C++
debugger. I want to set a breakpoint such that it will stop when some
specific heap address, say, 0x12345678, is allocated or freed. Is there
any way to do this?

In breakpoint setting panel, I see "On Access...", from the word it
can do the job, then I input "0x12345678" on the condition field, but it
says some dbx error. I wonder what is the correct way to do this.

Thanks.

Jul 22 '05 #1
2 1996
John Black <bl***@eed.com> wrote:
Hi,
I am using Workshop in Forte Development 6 on Solaris as my C++
debugger. I want to set a breakpoint such that it will stop when some
specific heap address, say, 0x12345678, is allocated or freed. Is there
any way to do this?

In breakpoint setting panel, I see "On Access...", from the word it
can do the job, then I input "0x12345678" on the condition field, but it
says some dbx error. I wonder what is the correct way to do this.

Thanks.


An interesting question.
One possible solution is to set the breakpoint
at just before returning from malloc, and right after free is called.

Following is an example:

$ cat t.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
void * p = malloc(100);

printf("%x\n", p);

free(p);
return 0;
}
$ cc -g t.c
$ dbx ./a.out
Reading a.out
Reading ld.so.1
Reading libc.so.1
Reading libdl.so.1
Reading libc_psr.so.1
(dbx 1) stop in main
(2) stop in main
(dbx 2) run
Running: a.out
(process id 14122)
stopped in main at line 5 in file "t.c"
5 void * p = malloc(100);
(dbx 3) dis malloc
0x7fac1cb8: malloc : save %sp, -96, %sp
0x7fac1cbc: malloc+0x0004: call malloc+0xc ! 0x7fac1cc4
0x7fac1cc0: malloc+0x0008: sethi %hi(0x7a000), %o1
0x7fac1cc4: malloc+0x000c: inc 844, %o1
0x7fac1cc8: malloc+0x0010: add %o1, %o7, %o3
0x7fac1ccc: malloc+0x0014: ld [%o3 + 3788], %l0
0x7fac1cd0: malloc+0x0018: call _PROCEDURE_LINKAGE_TABLE_+0x3c
0x7fac1cd4: malloc+0x001c: mov %l0, %o0
0x7fac1cd8: malloc+0x0020: call _malloc_unlocked ! 0x7fac1cf4
0x7fac1cdc: malloc+0x0024: mov %i0, %o0
(dbx 4) dis
0x7fac1ce0: malloc+0x0028: mov %o0, %i0
0x7fac1ce4: malloc+0x002c: call _PROCEDURE_LINKAGE_TABLE_+0x48
0x7fac1ce8: malloc+0x0030: mov %l0, %o0
0x7fac1cec: malloc+0x0034: ret
0x7fac1cf0: malloc+0x0038: restore
0x7fac1cf4: _malloc_unlocked : save %sp, -96, %sp
0x7fac1cf8: _malloc_unlocked+0x0004: sethi %hi(0xffffdc00), %o0
0x7fac1cfc: _malloc_unlocked+0x0008: call _malloc_unlocked+0x10
0x7fac1d00: _malloc_unlocked+0x000c: sethi %hi(0x7a000), %o1
0x7fac1d04: _malloc_unlocked+0x0010: inc 999, %o0
(dbx 5) stopi at 0x7fac1cec -if $i0 == 0x20e38
(3) stopi at &malloc+0x34 -if $i0 == 0x20e38
(dbx 6) stop in free -if $o0 == 0x20e38
dbx: warning: 'free' has no debugger info -- will trigger on first instruction
(4) stop in free -if $o0 == 0x20e38
(dbx 7) cont
stopped in malloc at 0x7fac1cec
0x7fac1cec: malloc+0x0034: ret
(dbx 8) up
Current function is main
5 void * p = malloc(100);
(dbx 9) cont
20e38
stopped in free at 0x7fac2b4c
0x7fac2b4c: free : save %sp, -96, %sp
Current function is main
9 free(p);
(dbx 10) cont

execution completed, exit code is 0
(dbx 11)
The first stopi point is at the "ret" instruction of malloc,
and stops only when $i0 (the return value, %i0 in disassembly)
is the value you want (in this case, 0x20e38).
The second stop point is at the first instruction of free (stop in free)
and only if $o0 (the first parameter) is the value you want.
(dbx 8) promt caught malloc() from returning 0x20e38,
and (dbx 10) caught free() being passed 0x20e38.

Depending on what you want to do, apptrace might be useful also.
with the same a.out:

$ apptrace ./a.out
apptrace: unexpected version: 3
a.out -> libc.so.1:atexit(func = 0x7fbaeaa8) = 0x0
a.out -> libc.so.1:atexit(func = 0x10c98) = 0x0
a.out -> libc.so.1:malloc(size = 0x64) = 0x20e38
a.out -> libc.so.1:printf(20e38
format = 0x10cb0, ...) = 6
a.out -> libc.so.1:free(ptr = 0x20e38)
a.out -> libc.so.1:exit(status = 0)
$

And of course, Dtrace in Solaris 10 can do what apptrace can do (and more).

Another useful tool is dbx's rtc checking (if that's what you're trying to do).
Just do:

(dbx 1) check -access

And it will do bunch of different runtime error checkings for memory allocation.
Type "help check" on dbx command line to see more detail.
--
#pragma ident "Seongbae Park, compiler, http://blogs.sun.com/seongbae/"
Jul 22 '05 #2
John Black <bl***@eed.com> wrote:
Hi,
I am using Workshop in Forte Development 6 on Solaris as my C++
debugger. I want to set a breakpoint such that it will stop when some
specific heap address, say, 0x12345678, is allocated or freed. Is there
any way to do this?

In breakpoint setting panel, I see "On Access...", from the word it
can do the job, then I input "0x12345678" on the condition field, but it
says some dbx error. I wonder what is the correct way to do this.

Thanks.


Just talked to our dbx engineer, and there's an easier alternative
than setting a breakpoint at the return instruction,
using "stop returns".

On SPARC:

(dbx) stop returns malloc -if $o0 == 0x12345678
(dbx) stop in free -if $o0 == 0x12345678

On x86:

(dbx) stop returns malloc -if $eax == 0x12345678
(dbx) stop in free -if *(void**)($sp + 1) == 0x12345678

This would do the trick nicely,
although the runtime overhead is somewhat more expensive
than the technique described in my previous posting
due to the way "returns" is implemented.
--
#pragma ident "Seongbae Park, compiler, http://blogs.sun.com/seongbae/"
Jul 22 '05 #3

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

Similar topics

0
by: akmal chaudhri | last post by:
Call for papers dataX International Workshop on Database Technologies for Handling XML information on the Web March 14, 2004, Heraklion, Crete (Greece) ...
0
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
0
by: Dana Morris | last post by:
Call for Participation OMG's First Annual Software-Based Communications (SBC) Workshop: From Mobile to Agile Communications http://www.omg.org/news/meetings/SBC2004/call.htm September 13-16,...
0
by: HarryHalpin | last post by:
IRW2006 - Identity, Reference, and the Web http://www.ibiblio.org/hhalpin/irw2006/ Co-located Workshop at WWW2006, Edinburgh Scotland, May First Call for Papers ===========
0
by: Wim Vanhoof | last post by:
----------------------------------------------------------- WLPE' 06 - CALL FOR PAPERS Workshop on Logic-based Methods in Programming Environments (satellite workshop of ICLP’06) August...
0
by: mmueller | last post by:
=== Reminder=== The deadline for submitting abstracts for the the workshop on September 8 in Leipzig is July 15. It is only two days away!! If you would like to give a presentation, please...
0
by: alexandre.bergel | last post by:
Dear colleges, You might want to consider Dyla'07 as a good venue to present your work and your favourite programming language. Regards, Alexandre ...
0
by: Wim Vanhoof | last post by:
----------------------------------------------------------- WLPE' 07 - CALL FOR PAPERS Workshop on Logic-based Methods in Programming Environments (satellite workshop of ICLP'07) ...
0
by: Alexandre Bergel | last post by:
Dear colleague, Please, note that after the workshop, best papers will be selected, and a second deadline will then be set regarding preparation of the Electronic Communications of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.