View into objects in watch whereever I am

G

Greg

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.
 
C

Ciaran O''Donnell

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.
 
B

Brian Rasmussen [C# MVP]

Greg said:
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.
 
G

Greg

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.
 
G

Greg

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.
 
I

Ignacio Machin ( .NET/ C# MVP )

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.
 
C

Ciaran O''Donnell

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 said:
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.
 
G

Greg

Hello Ignacio,

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.

Thats not true for me: A VC++ Project with VS2005.

Regards, Greg.
 
G

Greg

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();
}
};
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top