|
|
Home » U++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » Bug (?) in ide\Debuggers\Exp.cpp
Bug (?) in ide\Debuggers\Exp.cpp [message #3394] |
Tue, 23 May 2006 12:25 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
(I'm just trying to figure out why the "data[2]" does lead to "Only pointer can be dereferenced" ... still reading the Exp.cpp + parser.cpp classes, I will need probably some more time (like couple of days, as I have just couple of minutes per day for Ultimate++) to get familiar with those classes)
I found out suspicious code in Exp.cpp (line 136, 605dev1 src):
Pdb::Val Pdb::Compute(Pdb::Val v1, Pdb::Val v2, int oper)
{
if(v1.ref) {
int q = (int)GetInt(v2) * (v1.ref > 1 ? 4 : SizeOfType(v1.type));
v1 = GetRVal(v1);
switch(oper) {
case '+': v1.address += q; break;
case '-': v1.address -= q; break;
default: ThrowError("Invalid pointer arithmetics");
}
return v1;
}
if(v1.ref) {
int q = (int)GetInt(v1) * (v2.ref ? 4 : SizeOfType(v2.type));
v2 = GetRVal(v2);
if(oper == '+')
v2.address += q;
else
ThrowError("Invalid pointer arithmetics");
return v2;
}
Looks to me like the second if should be:
if (v2.ref) {
Besides that it looks to me like (almost) duplicite code... which I personally quite dislike, when it can be avoided easily.
Maybe some
Pdb::val & _v1 = v1;
Pdb::val & _v2 = v2;
if (!v1.ref && v2.ref) _v1 = v2, _v2 = v1;
//further _v1 and _v2 are used instead of v1/v2
would be more elegant and more powerful (supporting "-" operator even if v2 is "ref"), but I don't have enough insight into the code to judge whether the "more powerful" part is actually needed, or counterproductive. And it would maybe still look somewhat cumbersome anyway. (And I didn't try that proposal, so I'm not sure if it doesn't have some further catch.)
Edit: now I'm not sure if _v1 = v2 would not overwrite also original v1 content ... probably yes?
Once the reference is set, how to change it in C++?
I already forgot how references work exactly (as I do use plain C in work right now, for last year or so)... Maybe I should check the C++ language reference again.
[Updated on: Tue, 23 May 2006 12:29] Report message to a moderator
|
|
|
Re: Bug (?) in ide\Debuggers\Exp.cpp [message #3396 is a reply to message #3394] |
Tue, 23 May 2006 12:41 |
|
mirek
Messages: 13976 Registered: November 2005
|
Ultimate Member |
|
|
mr_ped wrote on Tue, 23 May 2006 06:25 | (I'm just trying to figure out why the "data[2]" does lead to "Only pointer can be dereferenced" ... still reading the Exp.cpp + parser.cpp classes, I will need probably some more time (like couple of days, as I have just couple of minutes per day for Ultimate++) to get familiar with those classes)
I found out suspicious code in Exp.cpp (line 136, 605dev1 src):
Pdb::Val Pdb::Compute(Pdb::Val v1, Pdb::Val v2, int oper)
{
if(v1.ref) {
int q = (int)GetInt(v2) * (v1.ref > 1 ? 4 : SizeOfType(v1.type));
v1 = GetRVal(v1);
switch(oper) {
case '+': v1.address += q; break;
case '-': v1.address -= q; break;
default: ThrowError("Invalid pointer arithmetics");
}
return v1;
}
if(v1.ref) {
int q = (int)GetInt(v1) * (v2.ref ? 4 : SizeOfType(v2.type));
v2 = GetRVal(v2);
if(oper == '+')
v2.address += q;
else
ThrowError("Invalid pointer arithmetics");
return v2;
}
Looks to me like the second if should be:
if (v2.ref) {
Besides that it looks to me like (almost) duplicite code... which I personally quite dislike, when it can be avoided easily.
Maybe some
Pdb::val & _v1 = v1;
Pdb::val & _v2 = v2;
if (!v1.ref && v2.ref) _v1 = v2, _v2 = v1;
//further _v1 and _v2 are used instead of v1/v2
would be more elegant and more powerful (supporting "-" operator even if v2 is "ref"), but I don't have enough insight into the code to judge whether the "more powerful" part is actually needed, or counterproductive. And it would maybe still look somewhat cumbersome anyway. (And I didn't try that proposal, so I'm not sure if it doesn't have some further catch.)
Edit: now I'm not sure if _v1 = v2 would not overwrite also original v1 content ... probably yes?
Once the reference is set, how to change it in C++?
I already forgot how references work exactly (as I do use plain C in work right now, for last year or so)... Maybe I should check the C++ language reference again.
|
Thanks!
Mirek
|
|
|
|
|
Re: Bug (?) in ide\Debuggers\Exp.cpp [message #7954 is a reply to message #3397] |
Thu, 01 February 2007 18:51 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
mr_ped wrote on Tue, 23 May 2006 14:00 | And changing the code to:
Pdb::Val Pdb::Compute(Pdb::Val v1, Pdb::Val v2, int oper)
{
if(v1.ref || v1.array) {
...
if(v2.ref || v2.array) {
...
does help in the debugger to allow me to use in Watches things like
data[2] upon data array.
Also works for arrays with elements larger than single byte, everything as expected.
@Mirek: any idea why the above mentioned modification od TheIDE may break something?
I've been thinking about it for a while, and I don't see any potentional harm by changing Pdb::Compute to work with arrays like with pointers...
IMHO working with them in any other way has no purpose, but you are the one to judge this.
If the change makes sense, add it to next dev realease.
Also I think some similar code is sitting somewhere in Assist, which is inhibiting it to work correctly with constructions like
Vector<byte> array_of_vectors[20];
(after array_of_vectors[0]. the Assist is lost and does not offer Vector<T> methods)
|
@Mirek: did this one make it into UPP?
I didn't check UPP for loooooong time, have been busy with other projects, but right now I'm searching for a C++ IDE for linux for commercial development, so I think I will watch UPP more closely again.
I hope you are glad I'm back. hehe (because I'm)
The last time I checked UPP (can't even remember the version number, must have been a year or so) this fix of array debugging was not added. If not, why not?
|
|
|
|
Goto Forum:
Current Time: Sat May 11 15:01:55 CEST 2024
Total time taken to generate the page: 0.02833 seconds
|
|
|