|
-
April 2nd, 2012, 03:08 PM
#1
What are some ways to trace a pointer ?
OS: Windows 7 64bit
IDE: Visual Studio 2008 (Express)
Hi I'm a novice C/C++ programmer, and right now I am trying to continue learning programming... I have started and
stopped a number of times in the past.
I am working with the codebase of "Blender 3D" which is a free open source 3D content creation suite ( Blender.org ). The codebase is mostly written in C. I have come across a situation in the code that is making things difficult. The PNL_CLOSED (#define PNL_CLOSED 6) bit is - disabled - within " block->panel->flag " whenever an end user opens a panel in Blender 3D; it must pass through an "if" statement just prior disablement. My problem is that at no point do I find where the PNL_CLOSED bit was enabled; it should be enabled whenever an end user closes a panel. Here is a code snippet:
Code:
if (block->panel->flag & PNL_CLOSED) {
block->panel->flag &= ~PNL_CLOSED;
I have used the "Find All References" feature within VS 2008, and none of the references seem to be enabling the
PNL_CLOSED bit.
=============QUESTIONS============================
1) Can Visual Studio 2008 trace pointers? (e.g. it can trace the hierarchy of classes and functions)
2) What are some ways to trace a pointer?
==================================================
Thanks a lot.... Good day to you.
Last edited by kmkkra; April 2nd, 2012 at 03:21 PM.
-
April 2nd, 2012, 03:48 PM
#2
Re: What are some ways to trace a pointer ?
You can set a data breakpoint to find when a variable is changed.
I did some browsing though and PNL_CLOSED isn't a bit, it's actually two bits.From interface_intern.h
Code:
#define PNL_CLOSEDX 2
#define PNL_CLOSEDY 4
#define PNL_CLOSED 6
In interface_panel.c the X & Y bits are set individually at line 1045 & 1049 (just below the code you posted)
-
April 2nd, 2012, 04:39 PM
#3
Re: What are some ways to trace a pointer ?
Wow! You actually took the time to look through the codebase......
I was going to post the file locations within the repository, but I wasn't sure that anybody would bother to look.
 Originally Posted by S_M_A
You can set a data breakpoint to find when a variable is changed.
Yeah. I set breakpoints out the yinyang, and was still finding this problem difficult to understand.
 Originally Posted by S_M_A
I did some browsing though and PNL_CLOSED isn't a bit, it's actually two bits.From interface_intern.h
Code:
#define PNL_CLOSEDX 2
#define PNL_CLOSEDY 4
#define PNL_CLOSED 6
In interface_panel.c the X & Y bits are set individually at line 1045 & 1049 (just below the code you posted)
Oh Okay... I think I get how it works now. The X and Y bits are being used to denote when a panel is closed. I was expecting that an operation
like " block->panel->flag |= PNL_CLOSED " would probably be used.
THANK YOU dude, I'm on my way to becoming a professional. Good day.
----------------------------------------
EDIT:
Oh yeah. You seem to have definitely solved my immediate problem (breathing a sigh of relief ). Thank you so much... But I was still wondering about the 2 questions in my original post; I - think - it might be very helpful to me in the future. Would you or anybody else have an answer?
Last edited by kmkkra; April 2nd, 2012 at 08:25 PM.
-
April 2nd, 2012, 11:13 PM
#4
Re: What are some ways to trace a pointer ?
 Originally Posted by S_M_A
You can set a data breakpoint to find when a variable is changed.
I might be speaking to soon, but upon further inspection I discovered that data breakpoints were a unique type of breakpoint. This type of break point - seems - to be exactly what I was asking for in my original 2 questions. I think...
Well S_M_A at first I guessed you right and then I second guessed you and thought by "data breakpoint" you meant just plain - breakpoint. But I went ahead and googled "data breakpoint" and found that it seems to be exactly what I was looking for.
Thank you again S_M_A. Of course, I am just both excited at all the new tools that I've recently discovered how to use and also impatient so I might be wrong about my expectations. If so, I will be bock
-
April 3rd, 2012, 12:24 AM
#5
Re: What are some ways to trace a pointer ?
Your welcome! 
If this solves the issue please also mark the thread as resolved (menu thread tools).
-
April 3rd, 2012, 05:58 PM
#6
Re: What are some ways to trace a pointer ?
After using the VS 2008 " Data Break Point" I've come to understand that their only functionality is to break execution when the value at such and such memory address is wrote to. One problem with this is that the memory may be freed without warning and then bound to a completely unrelated variable or pointer.
Also, I am trying to trace each location in code in which the address is read from, wrote to, assigned to reference &(C++ only), assigned to pointer. It would also be nice if there was a way to also trace any variable that recieves the value at that address.
And while we're at it, it would also be nice if there was a graph to visually display these connections/relationships (e.g. the Callers and Caller graph in VS 2008, Dot graphs in Doxygen, etc.) Of course, a graph is nice, but not completely necessary.
----------------------------------------------
Here is what I am trying to do right now.
In this file:
https://svn.blender.org/svnroot/bf-b...erface_panel.c
At this function:
static void ui_handle_panel_header( )
The member " block->panel->flag " is either enabled or disabled in order to expand or collapse panels within the " Blender 3D " user interface.
code snippet:
Code:
if (block->panel->flag & PNL_CLOSED) {
block->panel->flag &= ~PNL_CLOSED;
/* snap back up so full panel aligns with screen edge */
if (block->panel->snap & PNL_SNAP_BOTTOM)
block->panel->ofsy= 0;
}
else if (align==BUT_HORIZONTAL) {
block->panel->flag |= PNL_CLOSEDX;
}
else {
/* snap down to bottom screen edge*/
block->panel->flag |= PNL_CLOSEDY;
I am trying to find out where in Blender's codebase is the " block->panel->flag " value being used to test whether to draw a panel expanded or draw a panel collapsed. I think if there is a resolution to the questions below then that should help resolve the above scenario.
---------------------------------------------
Lastly, I am still interested in an answer to my questions in my first post above. So here are those questions again, but with a few changes.
==================QUESTIONS======================
1) Can Visual Studio 2008 or any software at all trace the usage (ANY usage at all) or appearance of a memory addess/pointer/variable within a codebase ?
(e.g. VS 2008, and Doxygen, etc., can trace the hierarchy of classes and functions)
2) What are some ways to trace a pointer?
3) How would - you - personally trace the usage of a variable or pointer within a codebase ?
(e.g. the data member " block->panel->flag " in the code snippet above)
================================================
If anyone else should happen to have an answer and help me - thanks. Good day.
Last edited by kmkkra; April 3rd, 2012 at 08:10 PM.
-
April 4th, 2012, 01:02 AM
#7
Re: What are some ways to trace a pointer ?
As far as I know...
1) VS (<= professional version) can't trace the usage of a variable or produce a full call graph. It has however the capability to show you all references to a function/method/variable and as you now know break on access.
Other Windows tools is available and static code analysis tools you might find as open source but expect tools that does the same in runtime or in a dynamic code analysis to be quite or very expensive. I've heard numbers like $100.000 for some tools...
2) A pointer is no different to any other variable.
3) In a well structured and well named code base an ordinary editor search very often is sufficent. Sometimes though one also need to use breakpoints and single stepping.
-
April 4th, 2012, 10:25 AM
#8
Re: What are some ways to trace a pointer ?
 Originally Posted by S_M_A
Other Windows tools is available and static code analysis tools you might find as open source but expect tools that does the same in runtime or in a dynamic code analysis to be quite or very expensive.
Well... I guess I'll be checkin' out some static code analysis tools then, and see what they can do. As far as runtime goes, I suppose that runtime analysis is not absolutely necessary, but it would be helpful though.
 Originally Posted by S_M_A
3) In a well structured and well named code base an ordinary editor search very often is sufficient. Sometimes though one also need to use breakpoints and single stepping.
I would think that professionals would be clamoring for any tool that could possibly make their jobs easier. But if you say the above is often sufficient then - I guess the above is often sufficient.
---
You know, I was thinking that one could use some of the functionality of a class to check when a class or it's data members are used. I'm thinkin' overloaded operators, constructor, destructor.... Maybe..? The section of code I'm working with right now is C, so I don't know that I can use C++ constructs.
--
I want to thank you again S_M_A for your time and answers. Your answers seem to resolve my questions yet I still can't decide if I want to mark this post as [RESOLVED] just yet. I think I'll wait a while and see if anyone has any other info they can think to give.
Thanks buddy, very good day to you!
Last edited by kmkkra; April 4th, 2012 at 03:14 PM.
-
April 4th, 2012, 02:15 PM
#9
Re: What are some ways to trace a pointer ?
 Originally Posted by kmkkra
I am trying to find out where in Blender's codebase is the " block->panel->flag " value being used to test whether to draw a panel expanded or draw a panel collapsed. I think if there is a resolution to the questions below then that should help resolve the above scenario.
---------------------------------------------
Lastly, I am still interested in an answer to my questions in my first post above. So here are those questions again, but with a few changes.
==================QUESTIONS======================
1) Can Visual Studio 2008 or any software at all trace the usage (ANY usage at all) or appearance of a memory addess/pointer/variable within a codebase ?
(e.g. VS 2008, and Doxygen, etc., can trace the hierarchy of classes and functions)
2) What are some ways to trace a pointer?
3) How would - you - personally trace the usage of a variable or pointer within a codebase ?
(e.g. the data member " block->panel->flag " in the code snippet above)
================================================
If anyone else should happen to have an answer and help me - thanks. Good day.
I don’t have an answer, but I do have an opinion.
If you want to control access to individual fields in your class or struct, make them private and provide accessor and mutator functions. That will let you inspect attempted change before it happens (and, possibly, reject it), as well as simply place breakpoints on these function to track callers.
This, of course, won’t catch out-of-bounds or “wild” access. If you have a pointer to an int, and assign some random value to it and access data at that location – not much can save you.
My understanding of how data breakpoints work is that debugger modifies an access rights to the memory page containing the address of interest, and that causes an exception when that page is written to. I am not sure what (if anything) can be done to capture reads though, but even if you can – that will slow your debugger to a crawl.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|