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

View into objects in watch whereever I am

Dear all,

I've trouble with debugging a huge programm.
I want to look into the properties of an object when I am at a breakpoint.
But in the watch window he tell's me that the object is "out of scope".
Two questions:
1.) Is there a way to look into an instance of an object even if it is not
"visible" to the actual method.
(Only with the watch window of the debugger)
I know there is only one instance in the hole application.
(In more basic programming environments it is possible to detect the address
of the object - e.g. at generation - and
then make a cast to the memory address so that i can see the object in the
watch window
whenever i want)
2.) Is there a way to make the object "global" so that I can have a
possibility to look into it.
(he's complaining that I can't make a gc object global)

Many thanks for all suggestions,

Greg.
Jul 25 '08 #1
8 1657
If you create a static reference to it in a singleton type way. You would be
able to watch that as it would be in scope anywhere in the same app domain.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Greg" wrote:
Dear all,

I've trouble with debugging a huge programm.
I want to look into the properties of an object when I am at a breakpoint.
But in the watch window he tell's me that the object is "out of scope".
Two questions:
1.) Is there a way to look into an instance of an object even if it is not
"visible" to the actual method.
(Only with the watch window of the debugger)
I know there is only one instance in the hole application.
(In more basic programming environments it is possible to detect the address
of the object - e.g. at generation - and
then make a cast to the memory address so that i can see the object in the
watch window
whenever i want)
2.) Is there a way to make the object "global" so that I can have a
possibility to look into it.
(he's complaining that I can't make a gc object global)

Many thanks for all suggestions,

Greg.
Jul 25 '08 #2
Greg wrote:
Dear all,

I've trouble with debugging a huge programm.
I want to look into the properties of an object when I am at a breakpoint.
But in the watch window he tell's me that the object is "out of scope".
Two questions:
1.) Is there a way to look into an instance of an object even if it is not
"visible" to the actual method.
(Only with the watch window of the debugger)
I know there is only one instance in the hole application.
(In more basic programming environments it is possible to detect the address
of the object - e.g. at generation - and
then make a cast to the memory address so that i can see the object in the
watch window
whenever i want)
2.) Is there a way to make the object "global" so that I can have a
possibility to look into it.
(he's complaining that I can't make a gc object global)

Many thanks for all suggestions,

Greg.

If you want to observe an out of scope instance, you can do the
following. When the object is in scope, add a watch to it. Then right
click on the reference in the watch window and select make object id.

This will assign an object id to the instance. The object id is listed
next to the current value in the value column. Object ids are numbered,
so the first object id will be 1# and so forth.

Now add a reference in the watch window for 1#. This will allow you to
inspect objects that are out of scope. You can even modify the instance
via this reference. However, the watch window will not keep the instance
alive, so if garbage collection occurs you will lose it.

--
Regards,
Brian Rasmussen [C# MVP]
kodehoved.dk
Jul 25 '08 #3
Hello Brian,

You suggestion sounds great to me but when i "right click"
the object in the watch i only get the following options:
- copy
- insert
- change value (greyed out)
- add to watch
- delete form watch
- select all
- delete all
- hexadecimal view
- reduce element (greyed out)
(may the englisch terms are differ as i've german i tried to translate)

I work with VS2005 is this option of VS2008 ?

Thanks for your suggestion,
Greg.

If you want to observe an out of scope instance, you can do the following.
When the object is in scope, add a watch to it. Then right click on the
reference in the watch window and select make object id.

This will assign an object id to the instance. The object id is listed
next to the current value in the value column. Object ids are numbered, so
the first object id will be 1# and so forth.

Now add a reference in the watch window for 1#. This will allow you to
inspect objects that are out of scope. You can even modify the instance
via this reference. However, the watch window will not keep the instance
alive, so if garbage collection occurs you will lose it.

--
Regards,
Brian Rasmussen [C# MVP]
kodehoved.dk

Jul 25 '08 #4
Thanks Ciaran for the Keyword "Singleton".
I may try to convert the object to a singleton but it seems heavy to me.
It is in fact the "global program dataset".
So the root-object could be "static" (which i suggest is demaded for beeing
a singleton)
but the incorporated data consists of variing lists of objects which are
(and must be) gc.
So i'm not sure if i can make this "singleton"

Anyway thanks for the suggestion as I didn't know this
"keyword".

Regards,
Greg.

"Ciaran O''Donnell" <Ci************@discussions.microsoft.comschrieb im
Newsbeitrag news:D2**********************************@microsof t.com...
If you create a static reference to it in a singleton type way. You would
be
able to watch that as it would be in scope anywhere in the same app
domain.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com

Jul 25 '08 #5
On Jul 25, 5:01*am, "Greg" <G...@nospam.cawrote:
Dear all,

I've trouble with debugging a huge programm.
I want to look into the properties of an object when I am at a breakpoint..
But in the watch window he tell's me that the object is "out of scope".
Two questions:
1.) Is there a way to look into an instance of an object even if it is not
"visible" to the actual method.
Why you want to do this? If the isntance of that object is not in
scope the values of it will have no effect at all.
IIRC you still see the values in the watch window but they cannot be
changed.
Jul 25 '08 #6
you could just add the static reference for debugging, and remove it in the
release version of the code. Having a static reference will enable you to
watch it anywhere. You wouldnt have to use it as a singleton unless you
decided that was what you needed.
Btw, objects referenced by a static object will be suitable for garbage
collection if that object is nulled ( e.g myob=null;) and nothing else holds
a reference.

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Greg" wrote:
Thanks Ciaran for the Keyword "Singleton".
I may try to convert the object to a singleton but it seems heavy to me.
It is in fact the "global program dataset".
So the root-object could be "static" (which i suggest is demaded for beeing
a singleton)
but the incorporated data consists of variing lists of objects which are
(and must be) gc.
So i'm not sure if i can make this "singleton"

Anyway thanks for the suggestion as I didn't know this
"keyword".

Regards,
Greg.

"Ciaran O''Donnell" <Ci************@discussions.microsoft.comschrieb im
Newsbeitrag news:D2**********************************@microsof t.com...
If you create a static reference to it in a singleton type way. You would
be
able to watch that as it would be in scope anywhere in the same app
domain.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com


Jul 26 '08 #7
Hello Ignacio,
>>Why you want to do this? If the isntance of that object is not in
scope the values of it will have no effect at all.
I search for a bug in a little bigger software. Due to some yet unkown bugs
the
software enters a state which should be normally unreachable.
I know when the bug occurs. There is a refresh of a drawing.
But values for drawing are taken from an access procedure like:
GivePointerToStatusObject()->GiveValueA() where A is a private member
of the status Object which is itself not directly accessed but through the
"GivePointerToStatusObject()" method. As i can't add "GiveValueA()" to
the watch window and get A. And as there are also other objects which
would be interesting to know it would be very nice to have the oportunity
to see all objects (or at least the major ones) of the Programm at the point
where I am.
In non-object oriented programming this is easyly possible.
>>IIRC you still see the values in the watch window but they cannot be
changed.
Thats not true for me: A VC++ Project with VS2005.

Regards, Greg.

Jul 28 '08 #8
Hello Ciaran,

Excuse may you can help me a little bit more:
I created a very tiny project with a form and a button on it.
It has two classes each with one int as private property and access
functions (Get/Set).
My problem is like this:
I've a breakpoint in "myClassB->SetmyClassBVariable(7);" in the button
routine. So
my "program counter" is at:
myClassBVariable = what;
Now I want to know what is the Variable in myClassA now - Which is not
possible to me.
I tried something with static with the "watchIt" of Type MyClassA.
But it doesn't work also.
I thought when I am at the breakpoint in line "myClassBVariable = what;" i
could access everything
(at least visualise it) as it definitely is somewhere in the RAM.

Would be nice if you or
someoneelse could help me with my misunderstandings,

Regards, Greg.

P.S.: The real project is indeed somewhat more complicated. ClassA has a
static method returning the instance
of the object which is more than obscure to me - but o.k. it works so I'm
not interested in.
The only thing which does not fit into my mind is that it should be possible
to inspect every tiny variable in the program
as there value's positions in RAM are known to the debugger ?!.

-------------------------------------------------------------------------------------------------------------------
This is a small project explaining my problem:
-------------------------------------------------------------------------------------------------------------------
#pragma once
namespace Test5 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

public class MyClassA
{
public: void SetmyClassAVariable(int what) {myClassAVariable = what;}
public: int GetmyClassAVariable(void) {return myClassAVariable;}
private: int myClassAVariable;
};

public class MyClassB
{
public: void SetmyClassBVariable(int what)
{
myClassBVariable = what;// make Breakpoint here at ButtonClick and try to
watch the other classA variables.************************
}
private: int myClassBVariable;
};

/// <summary>
/// Zusammenfassung für Form1
///
/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
/// die Ressourcendateiname-Eigenschaft für das Tool zur
Kompilierung verwalteter Ressourcen ändern,
/// das allen RESX-Dateien zugewiesen ist, von denen diese Klasse
abhängt.
/// Anderenfalls können die Designer nicht korrekt mit den
lokalisierten Ressourcen
/// arbeiten, die diesem Formular zugewiesen sind.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
private: MyClassA * myClassA;
private: MyClassB * myClassB;

public: static MyClassA * watchIt;
public:
Form1(void)
{
myClassA = new MyClassA();
myClassA->SetmyClassAVariable(5);
myClassB = new MyClassB();
watchIt = new MyClassA();
watchIt->SetmyClassAVariable(100);
watchIt = myClassA;
InitializeComponent();
//
//TODO: Konstruktorcode hier hinzufügen.
//
}

protected:
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(12, 12);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this,
&Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);

}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
myClassB->SetmyClassBVariable(7);
button1->Text = watchIt->GetmyClassAVariable().ToString();
}
};
}


Jul 28 '08 #9

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

Similar topics

1
by: Fran?ois Bourdages | last post by:
Hi is there a way to know if object (view, function, etc) are invalid ? let say a have a table t1 (field col1, col2) and a view v1 (field t1.col1, t1.col2) if I drop t1.col2, the view v1 is not...
11
by: Paul Reddin | last post by:
Hi, This is a real hopeful one! What we are trying to do: 1. We MUST present a mappable database object for our application objects i.e a Table or a View Some of the views are very...
4
by: Shadowboxer | last post by:
What happened to global objects? I want to make the main form accessible throughout all the classes as a single instance, right now I have to make a cludgy pass back through the class structure...
1
by: Mike | last post by:
Hi, I have created a collection of a custom class. Everything works fine (can add these items in a combo from within a VB.NET application, for instance), but when looking at the collection from a...
16
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
12
by: JoeC | last post by:
I am writing a program and I would like to pass an array of objects to a function and from that object I want to return a valuse to that function how do I do it? Here is what I have: terrain...
12
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use...
6
by: Bill44077 | last post by:
Hi, I am new to the MVP pattern and one of the main reasons that we are going this route is because we are doing Scrum with 30 day sprints - so we have a continually morphing design. We are...
9
by: Jazi | last post by:
Hello everyone, I was wondering if someone can help me figuring out some errors I keep getting when I try to create a dll library from existing c++ code using VS2005. The issue is related to a...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.