Windbg scripting - echo the class type of a variable
In Windbg I have a script that iterates through the frames of a stack and does a good job of pulling back things of interest, echoing them to the Command Window (it just sniffs things out that could require further investigation).
In certain frames, there will be a this
that I'm interested in some details of. I can certainly extract the details fine, but I'd like to get the actual class type from it too. I know that if I then do a dv /t
I will see something like the following:
0:115> .frame 14
0:115> dv /t
class foo1 * this = 0x00000000e9ed0010
I would like a way of being able to pass just foo1
to a .printf
command.
In frames that have more than simply this
, I can restrict output by using the pattern dv /t this
obviously, but is there a good way of having something like what follows in a frame and me being able to extract just foo1
?
0:115> .frame 17
0:115> dv /t
class foo1 * this = 0x00000000f3e2f568
class foo2 * bar2 = 0x0000000000000001
bool _somebool = true
Doing what follows is very close to the limited output I'd like... but I just want to neaten it up.
0:115> .frame 17
0:115> dv /t this
class foo1 * this = 0x00000000f3e2f568
Following the example code from blabb:
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> some command
Time
The third command is what I'm looking for.
class types scripting windbg
add a comment |
In Windbg I have a script that iterates through the frames of a stack and does a good job of pulling back things of interest, echoing them to the Command Window (it just sniffs things out that could require further investigation).
In certain frames, there will be a this
that I'm interested in some details of. I can certainly extract the details fine, but I'd like to get the actual class type from it too. I know that if I then do a dv /t
I will see something like the following:
0:115> .frame 14
0:115> dv /t
class foo1 * this = 0x00000000e9ed0010
I would like a way of being able to pass just foo1
to a .printf
command.
In frames that have more than simply this
, I can restrict output by using the pattern dv /t this
obviously, but is there a good way of having something like what follows in a frame and me being able to extract just foo1
?
0:115> .frame 17
0:115> dv /t
class foo1 * this = 0x00000000f3e2f568
class foo2 * bar2 = 0x0000000000000001
bool _somebool = true
Doing what follows is very close to the limited output I'd like... but I just want to neaten it up.
0:115> .frame 17
0:115> dv /t this
class foo1 * this = 0x00000000f3e2f568
Following the example code from blabb:
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> some command
Time
The third command is what I'm looking for.
class types scripting windbg
add a comment |
In Windbg I have a script that iterates through the frames of a stack and does a good job of pulling back things of interest, echoing them to the Command Window (it just sniffs things out that could require further investigation).
In certain frames, there will be a this
that I'm interested in some details of. I can certainly extract the details fine, but I'd like to get the actual class type from it too. I know that if I then do a dv /t
I will see something like the following:
0:115> .frame 14
0:115> dv /t
class foo1 * this = 0x00000000e9ed0010
I would like a way of being able to pass just foo1
to a .printf
command.
In frames that have more than simply this
, I can restrict output by using the pattern dv /t this
obviously, but is there a good way of having something like what follows in a frame and me being able to extract just foo1
?
0:115> .frame 17
0:115> dv /t
class foo1 * this = 0x00000000f3e2f568
class foo2 * bar2 = 0x0000000000000001
bool _somebool = true
Doing what follows is very close to the limited output I'd like... but I just want to neaten it up.
0:115> .frame 17
0:115> dv /t this
class foo1 * this = 0x00000000f3e2f568
Following the example code from blabb:
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> some command
Time
The third command is what I'm looking for.
class types scripting windbg
In Windbg I have a script that iterates through the frames of a stack and does a good job of pulling back things of interest, echoing them to the Command Window (it just sniffs things out that could require further investigation).
In certain frames, there will be a this
that I'm interested in some details of. I can certainly extract the details fine, but I'd like to get the actual class type from it too. I know that if I then do a dv /t
I will see something like the following:
0:115> .frame 14
0:115> dv /t
class foo1 * this = 0x00000000e9ed0010
I would like a way of being able to pass just foo1
to a .printf
command.
In frames that have more than simply this
, I can restrict output by using the pattern dv /t this
obviously, but is there a good way of having something like what follows in a frame and me being able to extract just foo1
?
0:115> .frame 17
0:115> dv /t
class foo1 * this = 0x00000000f3e2f568
class foo2 * bar2 = 0x0000000000000001
bool _somebool = true
Doing what follows is very close to the limited output I'd like... but I just want to neaten it up.
0:115> .frame 17
0:115> dv /t this
class foo1 * this = 0x00000000f3e2f568
Following the example code from blabb:
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> some command
Time
The third command is what I'm looking for.
class types scripting windbg
class types scripting windbg
edited Nov 22 at 9:48
asked Nov 20 at 11:04
Hippogriff
1341114
1341114
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
What I understood is: you need a command that takes foo1
as a parameter and gives an output like dv /t
but just for all foo1
.
IMHO, it's hardly possible with builtin WinDbg functionality. You could fiddle around with .foreach
inculding $spat
and the like.
One possibility is .shell
along with the command line tool findstr
or Cygwin grep
. But that's not convenient, because it always outputs Process started
etc. You could again work around this using .foreach
and skipping some tokens, but that's tedious.
There are grep
implementations for WinDbg such as long123king's grep plugin and if I recall correctly, there's also a grep implementation in PDE.
Then there is pykd, which has the powers of Python and let's you do basically anything.
add a comment |
i am not sure i understand what you need
but have you given the new dx expression evaluator a try
for example
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> dx @$curstack.Frames[0].LocalVariables
@$curstack.Frames[0].LocalVariables
this : 0x1efb24 [Type: Time *]
0:000> dx @$curstack.Frames[0].LocalVariables.this
@$curstack.Frames[0].LocalVariables.this : 0x1efb24 [Type: Time *]
[+0x000] hour : 23 [Type: int]
[+0x004] minute : 59 [Type: int]
[+0x008] second : 59 [Type: int]
you can enhance this with javascript to fine tune it to you needs
here is how you can enhance this with javascript
make a file whateverfoo.js
with contents below
function log(logstr) {
return host.diagnostics.debugLog(logstr + "n")
}
function locvartgttyp(frameno)
{
log( host.currentThread.Stack.Frames[frameno].LocalVariables.this.targetType.name)
}
and use it like
:>echo %wdbg%
"c:Program FilesWindows Kits10Debuggersx86cdb.exe"
:>%wdbg% time.exe
Microsoft (R) Windows Debugger Version 10.0.17763.132 X86
0:000> g time!main
time!main:
01237a80 55 push ebp
0:000> tc;t
time!Time::Time:
01231140 55 push ebp
0:000> dv /t
class Time * this = 0x00000002
int h = 0n23
int m = 0n59
int s = 0n59
0:000> .load jsprovider
0:000> .scriptload c:wdscrlocvar.js
JavaScript script successfully loaded from 'c:wdscrlocvar.js'
0:000> dx @$scriptContents.locvartgttyp(0)
Time *
@$scriptContents.locvartgttyp(0)
0:000>
What I unserstood is that he needs a command that takesfoo1
as a parameter, notthis
.
– Thomas Weller
Nov 20 at 19:34
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391610%2fwindbg-scripting-echo-the-class-type-of-a-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
What I understood is: you need a command that takes foo1
as a parameter and gives an output like dv /t
but just for all foo1
.
IMHO, it's hardly possible with builtin WinDbg functionality. You could fiddle around with .foreach
inculding $spat
and the like.
One possibility is .shell
along with the command line tool findstr
or Cygwin grep
. But that's not convenient, because it always outputs Process started
etc. You could again work around this using .foreach
and skipping some tokens, but that's tedious.
There are grep
implementations for WinDbg such as long123king's grep plugin and if I recall correctly, there's also a grep implementation in PDE.
Then there is pykd, which has the powers of Python and let's you do basically anything.
add a comment |
What I understood is: you need a command that takes foo1
as a parameter and gives an output like dv /t
but just for all foo1
.
IMHO, it's hardly possible with builtin WinDbg functionality. You could fiddle around with .foreach
inculding $spat
and the like.
One possibility is .shell
along with the command line tool findstr
or Cygwin grep
. But that's not convenient, because it always outputs Process started
etc. You could again work around this using .foreach
and skipping some tokens, but that's tedious.
There are grep
implementations for WinDbg such as long123king's grep plugin and if I recall correctly, there's also a grep implementation in PDE.
Then there is pykd, which has the powers of Python and let's you do basically anything.
add a comment |
What I understood is: you need a command that takes foo1
as a parameter and gives an output like dv /t
but just for all foo1
.
IMHO, it's hardly possible with builtin WinDbg functionality. You could fiddle around with .foreach
inculding $spat
and the like.
One possibility is .shell
along with the command line tool findstr
or Cygwin grep
. But that's not convenient, because it always outputs Process started
etc. You could again work around this using .foreach
and skipping some tokens, but that's tedious.
There are grep
implementations for WinDbg such as long123king's grep plugin and if I recall correctly, there's also a grep implementation in PDE.
Then there is pykd, which has the powers of Python and let's you do basically anything.
What I understood is: you need a command that takes foo1
as a parameter and gives an output like dv /t
but just for all foo1
.
IMHO, it's hardly possible with builtin WinDbg functionality. You could fiddle around with .foreach
inculding $spat
and the like.
One possibility is .shell
along with the command line tool findstr
or Cygwin grep
. But that's not convenient, because it always outputs Process started
etc. You could again work around this using .foreach
and skipping some tokens, but that's tedious.
There are grep
implementations for WinDbg such as long123king's grep plugin and if I recall correctly, there's also a grep implementation in PDE.
Then there is pykd, which has the powers of Python and let's you do basically anything.
edited Nov 20 at 19:37
answered Nov 20 at 15:39
Thomas Weller
28.3k1062135
28.3k1062135
add a comment |
add a comment |
i am not sure i understand what you need
but have you given the new dx expression evaluator a try
for example
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> dx @$curstack.Frames[0].LocalVariables
@$curstack.Frames[0].LocalVariables
this : 0x1efb24 [Type: Time *]
0:000> dx @$curstack.Frames[0].LocalVariables.this
@$curstack.Frames[0].LocalVariables.this : 0x1efb24 [Type: Time *]
[+0x000] hour : 23 [Type: int]
[+0x004] minute : 59 [Type: int]
[+0x008] second : 59 [Type: int]
you can enhance this with javascript to fine tune it to you needs
here is how you can enhance this with javascript
make a file whateverfoo.js
with contents below
function log(logstr) {
return host.diagnostics.debugLog(logstr + "n")
}
function locvartgttyp(frameno)
{
log( host.currentThread.Stack.Frames[frameno].LocalVariables.this.targetType.name)
}
and use it like
:>echo %wdbg%
"c:Program FilesWindows Kits10Debuggersx86cdb.exe"
:>%wdbg% time.exe
Microsoft (R) Windows Debugger Version 10.0.17763.132 X86
0:000> g time!main
time!main:
01237a80 55 push ebp
0:000> tc;t
time!Time::Time:
01231140 55 push ebp
0:000> dv /t
class Time * this = 0x00000002
int h = 0n23
int m = 0n59
int s = 0n59
0:000> .load jsprovider
0:000> .scriptload c:wdscrlocvar.js
JavaScript script successfully loaded from 'c:wdscrlocvar.js'
0:000> dx @$scriptContents.locvartgttyp(0)
Time *
@$scriptContents.locvartgttyp(0)
0:000>
What I unserstood is that he needs a command that takesfoo1
as a parameter, notthis
.
– Thomas Weller
Nov 20 at 19:34
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
add a comment |
i am not sure i understand what you need
but have you given the new dx expression evaluator a try
for example
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> dx @$curstack.Frames[0].LocalVariables
@$curstack.Frames[0].LocalVariables
this : 0x1efb24 [Type: Time *]
0:000> dx @$curstack.Frames[0].LocalVariables.this
@$curstack.Frames[0].LocalVariables.this : 0x1efb24 [Type: Time *]
[+0x000] hour : 23 [Type: int]
[+0x004] minute : 59 [Type: int]
[+0x008] second : 59 [Type: int]
you can enhance this with javascript to fine tune it to you needs
here is how you can enhance this with javascript
make a file whateverfoo.js
with contents below
function log(logstr) {
return host.diagnostics.debugLog(logstr + "n")
}
function locvartgttyp(frameno)
{
log( host.currentThread.Stack.Frames[frameno].LocalVariables.this.targetType.name)
}
and use it like
:>echo %wdbg%
"c:Program FilesWindows Kits10Debuggersx86cdb.exe"
:>%wdbg% time.exe
Microsoft (R) Windows Debugger Version 10.0.17763.132 X86
0:000> g time!main
time!main:
01237a80 55 push ebp
0:000> tc;t
time!Time::Time:
01231140 55 push ebp
0:000> dv /t
class Time * this = 0x00000002
int h = 0n23
int m = 0n59
int s = 0n59
0:000> .load jsprovider
0:000> .scriptload c:wdscrlocvar.js
JavaScript script successfully loaded from 'c:wdscrlocvar.js'
0:000> dx @$scriptContents.locvartgttyp(0)
Time *
@$scriptContents.locvartgttyp(0)
0:000>
What I unserstood is that he needs a command that takesfoo1
as a parameter, notthis
.
– Thomas Weller
Nov 20 at 19:34
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
add a comment |
i am not sure i understand what you need
but have you given the new dx expression evaluator a try
for example
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> dx @$curstack.Frames[0].LocalVariables
@$curstack.Frames[0].LocalVariables
this : 0x1efb24 [Type: Time *]
0:000> dx @$curstack.Frames[0].LocalVariables.this
@$curstack.Frames[0].LocalVariables.this : 0x1efb24 [Type: Time *]
[+0x000] hour : 23 [Type: int]
[+0x004] minute : 59 [Type: int]
[+0x008] second : 59 [Type: int]
you can enhance this with javascript to fine tune it to you needs
here is how you can enhance this with javascript
make a file whateverfoo.js
with contents below
function log(logstr) {
return host.diagnostics.debugLog(logstr + "n")
}
function locvartgttyp(frameno)
{
log( host.currentThread.Stack.Frames[frameno].LocalVariables.this.targetType.name)
}
and use it like
:>echo %wdbg%
"c:Program FilesWindows Kits10Debuggersx86cdb.exe"
:>%wdbg% time.exe
Microsoft (R) Windows Debugger Version 10.0.17763.132 X86
0:000> g time!main
time!main:
01237a80 55 push ebp
0:000> tc;t
time!Time::Time:
01231140 55 push ebp
0:000> dv /t
class Time * this = 0x00000002
int h = 0n23
int m = 0n59
int s = 0n59
0:000> .load jsprovider
0:000> .scriptload c:wdscrlocvar.js
JavaScript script successfully loaded from 'c:wdscrlocvar.js'
0:000> dx @$scriptContents.locvartgttyp(0)
Time *
@$scriptContents.locvartgttyp(0)
0:000>
i am not sure i understand what you need
but have you given the new dx expression evaluator a try
for example
0:000> dv /t
class Time * this = 0x001efb24
int h = 0n23
int m = 0n59
int s = 0n59
0:000> dv /t this
class Time * this = 0x001efb24
0:000> dx @$curstack.Frames[0].LocalVariables
@$curstack.Frames[0].LocalVariables
this : 0x1efb24 [Type: Time *]
0:000> dx @$curstack.Frames[0].LocalVariables.this
@$curstack.Frames[0].LocalVariables.this : 0x1efb24 [Type: Time *]
[+0x000] hour : 23 [Type: int]
[+0x004] minute : 59 [Type: int]
[+0x008] second : 59 [Type: int]
you can enhance this with javascript to fine tune it to you needs
here is how you can enhance this with javascript
make a file whateverfoo.js
with contents below
function log(logstr) {
return host.diagnostics.debugLog(logstr + "n")
}
function locvartgttyp(frameno)
{
log( host.currentThread.Stack.Frames[frameno].LocalVariables.this.targetType.name)
}
and use it like
:>echo %wdbg%
"c:Program FilesWindows Kits10Debuggersx86cdb.exe"
:>%wdbg% time.exe
Microsoft (R) Windows Debugger Version 10.0.17763.132 X86
0:000> g time!main
time!main:
01237a80 55 push ebp
0:000> tc;t
time!Time::Time:
01231140 55 push ebp
0:000> dv /t
class Time * this = 0x00000002
int h = 0n23
int m = 0n59
int s = 0n59
0:000> .load jsprovider
0:000> .scriptload c:wdscrlocvar.js
JavaScript script successfully loaded from 'c:wdscrlocvar.js'
0:000> dx @$scriptContents.locvartgttyp(0)
Time *
@$scriptContents.locvartgttyp(0)
0:000>
edited Nov 22 at 17:11
answered Nov 20 at 19:31
blabb
5,1121920
5,1121920
What I unserstood is that he needs a command that takesfoo1
as a parameter, notthis
.
– Thomas Weller
Nov 20 at 19:34
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
add a comment |
What I unserstood is that he needs a command that takesfoo1
as a parameter, notthis
.
– Thomas Weller
Nov 20 at 19:34
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
What I unserstood is that he needs a command that takes
foo1
as a parameter, not this
.– Thomas Weller
Nov 20 at 19:34
What I unserstood is that he needs a command that takes
foo1
as a parameter, not this
.– Thomas Weller
Nov 20 at 19:34
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
I edited my question to illustrate what I'd been wanting; apologies if my initial question was not clear enough.
– Hippogriff
Nov 22 at 9:48
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
i am still not sure of your intention i hope you understand Time * ! = Time any way i added a javascript enhancement as i earlier replied take a look
– blabb
Nov 22 at 17:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391610%2fwindbg-scripting-echo-the-class-type-of-a-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown