RE: SPAM-LOW: Re: Debugging issue to watch variable values

http://www.codeproject.com/KB/threads/StackWalker.aspx

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lin George
Sent: Thursday, September 25, 2008 14:08
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Subject: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values

Thanks Martin!

Actually I have read this, but it only covers the format of PDB file in a
very high level (e.g. into blocks and streams), not mentioned how debugger
utilizing PDB file to work. Any comments? Do you have any brief description
of how debugger utilizing PDB file? :slight_smile:

http://www.informit.com/articles/article.aspx?p=22685

regards,
George

----- Original Message ----
From: Martin O’Brien
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:02:05 PM
Subject: Re:[windbg] Debugging issue to watch variable values

I don’t know if it is still published, but ‘Undocumented Windows 2000
Secrets’ covers part of this.? There’s not a whole lot out
there that discusses this subject.

Good luck,

mm

Lin George wrote:
> Thanks Skywing,
>
>
> 1.
>
> So you think my issue of watching variables in release x64 mode with
optimized code is, PDB file has limitation which could not correctly
reflects the values in registers?
>
> 2.
>
> I am interested in how debugger could utilize information in PDB file to
find related symbol related to some binary code. And also how to find
related source code. I have made quite some search, but few good
documents/articles. Do you have any of such materials to recommend to read?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Skywing
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 8:49:28 PM
> Subject: RE: [windbg] Debugging issue to watch variable values
>
> To reiterate what I said earlier, as far as I know, the debug info
format’s support for locals is based on the assumption that they are stack
based.
>
> This is a limitation of the current tools, and not so much of any
fundamental technical roadblock aside from the fact that it’s not how things
were written to work.
>
> This is why debug builds always try and put locals on the stack instead of
exclusively saving them in a register.
>
> The .pdb is built at code generation time.? Think of it as reflecting a
view of locals before the optimizer has had a chance to figure out that some
locals do not need to live on the stack at all, but may reside exclusively
in a register.
>
> - S
>
> -----Original Message-----
> From: Lin George
> Sent: Thursday, September 25, 2008 01:07
> To: Skywing
> Cc: Kernel Debugging Interest List
> Subject: Re: [windbg] Debugging issue to watch variable values
>
>
> Thanks Skywing,
>
>
> 1.
>
> I think PDB is generated at compile/link time, correct?
>
>
> I listed my confusions in 2 and 3, but I do not know which one is correct.
Any comments?
>
> 2.
>
> If yes to 1, then during compile/link time, whether variable will be put
on stack or in register is still not decided, only during runtime will the
location (whether variable on stack or in register) be decided. – So that
the generated PDB is not matching the exact situation (e.g. PDB may think
some variable on stack, but actually it is in register), which cause the
wrong variable value during debugging?
>
> 3.
>
> If yes to 1, then during compile/link time, whether variable will be put
on stack or in register is still be decided, but PDB will completely ignore
such information in register.? – So that the generated PDB is not matching
the exact situation (e.g. PDB may think some variable on stack, but actually
it is in register), which cause the wrong variable value during debugging?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Skywing
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 1:11:17 PM
> Subject: RE: [windbg] Debugging issue to watch variable values
>
> .pdb is the debug file information format which contains symbol and type
info (including line number mappings) for a binary.
>
> As far as I know, the current .pdb formats only describe locals in terms
of stack locations and not registers.? Thus, for locals (including function
arguments) that get moved into registers, this fact is not recorded in a
usable way that would allow the debugger to track this.
>
> The bottom line is that when you have parameters and locals being moved
into registers, they will not show correct values in the local variable
display in the debugger.? The only guaranteed reliable way to do it is to
look at the actual disassembly and figure out what variables are going
where.
>
> - S
>
> -----Original Message-----
> From: Lin George [mailto:xxxxx@yahoo.com]
> Sent: Thursday, September 25, 2008 12:50 AM
> To: Skywing
> Cc: Kernel Debugging Interest List
> Subject: Re: [windbg] Debugging issue to watch variable values
>
> Hi Skywing,
>
>
> 1.
>
> My confusion is what is the relationshp between PDB and source code, in
what mechanisms do PDB and source code establish mapping relationship?
>
> 2.
>
> “This is because PDB does not allow reliable tracking of variables that
get cached in registers” – I always think PDB is 100% match binary even if
optimized code, but seems not?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Skywing
> To: Kernel Debugging Interest List
> Sent: Wednesday, September 24, 2008 9:58:05 PM
> Subject: RE: [windbg] Debugging issue to watch variable values
>
> This is because PDB does not allow reliable tracking of variables that get
cached in registers.
>
> You should be analyzing the code manually in this case.
>
> Local variable support is only reliable when you are doing source line
stepping in a non-optimized debug build.
>
> - S
>
> -----Original Message-----
> From: Lin George
> Sent: Wednesday, September 24, 2008 05:09
> To: Kernel Debugging Interest List
> Subject: [windbg] Debugging issue to watch variable values
>
>
> Hello everyone,
>
>
> 1.
>
> Sometimes in x64 release code (optimized to full level), even if we
defined some global data, variables or member variables for some data
structures, we can not see the actual value in debugger. The related error
message is – “Error: expression cannot be evaluated”.
>
> I think it is because of x64 code optimization to remove some variables or
changed code execution path?
>
> 2.
>
> Any ways to “watch” such variables? Currently I am just looking at the
asembly code to find what the actual execution is. For example, in source
code I pass variable foo to function SetValue, but since in debugger I can
not watch such variable foo, then I go to assembly code to watch what values
are passed to function SetValue through register or stack.
>
> Any better ideas to debug such x64 optimized code? Is it a common issue in
debugging x64 release code?
>
>
> thanks in advance,
> George
>
>
>
>
> —
> You are currently subscribed to windbg as: xxxxx@valhallalegends.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>? ? ?
>


You are currently subscribed to windbg as: xxxxx@yahoo.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Information from ESET NOD32 Antivirus, version of virus signature
database 3471 (20080925)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Skywing has answered that one already as well - read about DbgEng/DbgHelp in the documentation.

I’m not sure what you’re looking for if you think that is a high level description.

mm

Crispin Wright wrote:

http://www.codeproject.com/KB/threads/StackWalker.aspx

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lin George
Sent: Thursday, September 25, 2008 14:08
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Subject: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values

Thanks Martin!

Actually I have read this, but it only covers the format of PDB file in a
very high level (e.g. into blocks and streams), not mentioned how debugger
utilizing PDB file to work. Any comments? Do you have any brief description
of how debugger utilizing PDB file? :slight_smile:

http://www.informit.com/articles/article.aspx?p=22685

regards,
George

----- Original Message ----
From: Martin O’Brien
> To: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 9:02:05 PM
> Subject: Re:[windbg] Debugging issue to watch variable values
>
> I don’t know if it is still published, but ‘Undocumented Windows 2000
> Secrets’ covers part of this. There’s not a whole lot out
> there that discusses this subject.
>
> Good luck,
>
> mm
>
>
>
> Lin George wrote:
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> So you think my issue of watching variables in release x64 mode with
> optimized code is, PDB file has limitation which could not correctly
> reflects the values in registers?
>> 2.
>>
>> I am interested in how debugger could utilize information in PDB file to
> find related symbol related to some binary code. And also how to find
> related source code. I have made quite some search, but few good
> documents/articles. Do you have any of such materials to recommend to read?
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 8:49:28 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> To reiterate what I said earlier, as far as I know, the debug info
> format’s support for locals is based on the assumption that they are stack
> based.
>> This is a limitation of the current tools, and not so much of any
> fundamental technical roadblock aside from the fact that it’s not how things
> were written to work.
>> This is why debug builds always try and put locals on the stack instead of
> exclusively saving them in a register.
>> The .pdb is built at code generation time. Think of it as reflecting a
> view of locals before the optimizer has had a chance to figure out that some
> locals do not need to live on the stack at all, but may reside exclusively
> in a register.
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Thursday, September 25, 2008 01:07
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>>
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> I think PDB is generated at compile/link time, correct?
>>
>>
>> I listed my confusions in 2 and 3, but I do not know which one is correct.
> Any comments?
>> 2.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still not decided, only during runtime will the
> location (whether variable on stack or in register) be decided. – So that
> the generated PDB is not matching the exact situation (e.g. PDB may think
> some variable on stack, but actually it is in register), which cause the
> wrong variable value during debugging?
>> 3.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still be decided, but PDB will completely ignore
> such information in register. – So that the generated PDB is not matching
> the exact situation (e.g. PDB may think some variable on stack, but actually
> it is in register), which cause the wrong variable value during debugging?
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 1:11:17 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> .pdb is the debug file information format which contains symbol and type
> info (including line number mappings) for a binary.
>> As far as I know, the current .pdb formats only describe locals in terms
> of stack locations and not registers. Thus, for locals (including function
> arguments) that get moved into registers, this fact is not recorded in a
> usable way that would allow the debugger to track this.
>> The bottom line is that when you have parameters and locals being moved
> into registers, they will not show correct values in the local variable
> display in the debugger. The only guaranteed reliable way to do it is to
> look at the actual disassembly and figure out what variables are going
> where.
>> - S
>>
>> -----Original Message-----
>> From: Lin George [mailto:xxxxx@yahoo.com]
>> Sent: Thursday, September 25, 2008 12:50 AM
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>> Hi Skywing,
>>
>>
>> 1.
>>
>> My confusion is what is the relationshp between PDB and source code, in
> what mechanisms do PDB and source code establish mapping relationship?
>> 2.
>>
>> “This is because PDB does not allow reliable tracking of variables that
> get cached in registers” – I always think PDB is 100% match binary even if
> optimized code, but seems not?
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Sent: Wednesday, September 24, 2008 9:58:05 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> This is because PDB does not allow reliable tracking of variables that get
> cached in registers.
>> You should be analyzing the code manually in this case.
>>
>> Local variable support is only reliable when you are doing source line
> stepping in a non-optimized debug build.
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Wednesday, September 24, 2008 05:09
>> To: Kernel Debugging Interest List
>> Subject: [windbg] Debugging issue to watch variable values
>>
>>
>> Hello everyone,
>>
>>
>> 1.
>>
>> Sometimes in x64 release code (optimized to full level), even if we
> defined some global data, variables or member variables for some data
> structures, we can not see the actual value in debugger. The related error
> message is – “Error: expression cannot be evaluated”.
>> I think it is because of x64 code optimization to remove some variables or
> changed code execution path?
>> 2.
>>
>> Any ways to “watch” such variables? Currently I am just looking at the
> asembly code to find what the actual execution is. For example, in source
> code I pass variable foo to function SetValue, but since in debugger I can
> not watch such variable foo, then I go to assembly code to watch what values
> are passed to function SetValue through register or stack.
>> Any better ideas to debug such x64 optimized code? Is it a common issue in
> debugging x64 release code?
>>
>> thanks in advance,
>> George
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: xxxxx@valhallalegends.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>
> —
> You are currently subscribed to windbg as: xxxxx@yahoo.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> Information from ESET NOD32 Antivirus, version of virus signature
> database 3471 (20080925)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

Hi Skywing,

It is good to learn from you PDB file not establish relasionship between binary and symbol, but also establish relasionship between binary/symbol/source code line number. Cool!

regards,
George

----- Original Message ----
From: Skywing
To: Lin George
Cc: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:04:53 PM
Subject: RE: [windbg] Debugging issue to watch variable values

Re: 1. To say this for the third time, yes, this is your problem. You have to manually look at the disassembly to figure out where things are - end of story.

Re: 2. I don’t know the specifics of the internal representation, but one assumes that there is a table somewhere that maps address ranges to a particular source file and line number. The .pdb debug info format is not documented.

The debugger uses DbgHelp for retrieving this information from symbol files. If you are interested in how those APIs are defined, then you need to go look at the DbgHelp documentation in MSDN. You will get more useful information from reading that documentation than asking here about how to work with symbols on your own.

- S

-----Original Message-----
From: Lin George
Sent: Thursday, September 25, 2008 07:56
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Thanks Skywing,

1.

So you think my issue of watching variables in release x64 mode with optimized code is, PDB file has limitation which could not correctly reflects the values in registers?

2.

I am interested in how debugger could utilize information in PDB file to find related symbol related to some binary code. And also how to find related source code. I have made quite some search, but few good documents/articles. Do you have any of such materials to recommend to read?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 8:49:28 PM
Subject: RE: [windbg] Debugging issue to watch variable values

To reiterate what I said earlier, as far as I know, the debug info format’s support for locals is based on the assumption that they are stack based.

This is a limitation of the current tools, and not so much of any fundamental technical roadblock aside from the fact that it’s not how things were written to work.

This is why debug builds always try and put locals on the stack instead of exclusively saving them in a register.

The .pdb is built at code generation time. Think of it as reflecting a view of locals before the optimizer has had a chance to figure out that some locals do not need to live on the stack at all, but may reside exclusively in a register.

- S

-----Original Message-----
From: Lin George
Sent: Thursday, September 25, 2008 01:07
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Thanks Skywing,

1.

I think PDB is generated at compile/link time, correct?

I listed my confusions in 2 and 3, but I do not know which one is correct. Any comments?

2.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still not decided, only during runtime will the location (whether variable on stack or in register) be decided. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

3.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still be decided, but PDB will completely ignore such information in register. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 1:11:17 PM
Subject: RE: [windbg] Debugging issue to watch variable values

.pdb is the debug file information format which contains symbol and type info (including line number mappings) for a binary.

As far as I know, the current .pdb formats only describe locals in terms of stack locations and not registers. Thus, for locals (including function arguments) that get moved into registers, this fact is not recorded in a usable way that would allow the debugger to track this.

The bottom line is that when you have parameters and locals being moved into registers, they will not show correct values in the local variable display in the debugger. The only guaranteed reliable way to do it is to look at the actual disassembly and figure out what variables are going where.

- S

-----Original Message-----
From: Lin George [mailto:xxxxx@yahoo.com]
Sent: Thursday, September 25, 2008 12:50 AM
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Hi Skywing,

1.

My confusion is what is the relationshp between PDB and source code, in what mechanisms do PDB and source code establish mapping relationship?

2.

“This is because PDB does not allow reliable tracking of variables that get cached in registers” – I always think PDB is 100% match binary even if optimized code, but seems not?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Sent: Wednesday, September 24, 2008 9:58:05 PM
Subject: RE: [windbg] Debugging issue to watch variable values

This is because PDB does not allow reliable tracking of variables that get cached in registers.

You should be analyzing the code manually in this case.

Local variable support is only reliable when you are doing source line stepping in a non-optimized debug build.

- S

-----Original Message-----
From: Lin George
Sent: Wednesday, September 24, 2008 05:09
To: Kernel Debugging Interest List
Subject: [windbg] Debugging issue to watch variable values

Hello everyone,

1.

Sometimes in x64 release code (optimized to full level), even if we defined some global data, variables or member variables for some data structures, we can not see the actual value in debugger. The related error message is – “Error: expression cannot be evaluated”.

I think it is because of x64 code optimization to remove some variables or changed code execution path?

2.

Any ways to “watch” such variables? Currently I am just looking at the asembly code to find what the actual execution is. For example, in source code I pass variable foo to function SetValue, but since in debugger I can not watch such variable foo, then I go to assembly code to watch what values are passed to function SetValue through register or stack.

Any better ideas to debug such x64 optimized code? Is it a common issue in debugging x64 release code?

thanks in advance,
George


You are currently subscribed to windbg as: xxxxx@valhallalegends.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi Jim,

“the compiler is free to use that register for” – so the optimization of using register is decided at compile/link time, other than runtime? :slight_smile:

regards,
George

----- Original Message ----
From: Jim Donelson
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:28:33 PM
Subject: Re: [windbg] Debugging issue to watch variable values

In a release build with full optimization, it is not possible for the debugger to track a parameter passed in a register, the compiler is free to use that register for something else when that parameter is no longer needed, or to shuffle it to the stack as a temp or another register.

That why optimization is off for a debug build.

On Thu, Sep 25, 2008 at 8:49 AM, Skywing wrote:

To reiterate what I said earlier, as far as I know, the debug info format’s support for locals is based on the assumption that they are stack based.

This is a limitation of the current tools, and not so much of any fundamental technical roadblock aside from the fact that it’s not how things were written to work.

This is why debug builds always try and put locals on the stack instead of exclusively saving them in a register.

The .pdb is built at code generation time. Think of it as reflecting a view of locals before the optimizer has had a chance to figure out that some locals do not need to live on the stack at all, but may reside exclusively in a register.

- S

-----Original Message-----
From: Lin George
Sent: Thursday, September 25, 2008 01:07
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Thanks Skywing,

1.

I think PDB is generated at compile/link time, correct?

I listed my confusions in 2 and 3, but I do not know which one is correct. Any comments?

2.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still not decided, only during runtime will the location (whether variable on stack or in register) be decided. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

3.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still be decided, but PDB will completely ignore such information in register. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 1:11:17 PM
Subject: RE: [windbg] Debugging issue to watch variable values

.pdb is the debug file information format which contains symbol and type info (including line number mappings) for a binary.

As far as I know, the current .pdb formats only describe locals in terms of stack locations and not registers. Thus, for locals (including function arguments) that get moved into registers, this fact is not recorded in a usable way that would allow the debugger to track this.

The bottom line is that when you have parameters and locals being moved into registers, they will not show correct values in the local variable display in the debugger. The only guaranteed reliable way to do it is to look at the actual disassembly and figure out what variables are going where.

- S

-----Original Message-----
From: Lin George [mailto:xxxxx@yahoo.com]
Sent: Thursday, September 25, 2008 12:50 AM
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Hi Skywing,

1.

My confusion is what is the relationshp between PDB and source code, in what mechanisms do PDB and source code establish mapping relationship?

2.

“This is because PDB does not allow reliable tracking of variables that get cached in registers” – I always think PDB is 100% match binary even if optimized code, but seems not?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Sent: Wednesday, September 24, 2008 9:58:05 PM
Subject: RE: [windbg] Debugging issue to watch variable values

This is because PDB does not allow reliable tracking of variables that get cached in registers.

You should be analyzing the code manually in this case.

Local variable support is only reliable when you are doing source line stepping in a non-optimized debug build.

- S

-----Original Message-----
From: Lin George
Sent: Wednesday, September 24, 2008 05:09
To: Kernel Debugging Interest List
Subject: [windbg] Debugging issue to watch variable values

Hello everyone,

1.

Sometimes in x64 release code (optimized to full level), even if we defined some global data, variables or member variables for some data structures, we can not see the actual value in debugger. The related error message is – “Error: expression cannot be evaluated”.

I think it is because of x64 code optimization to remove some variables or changed code execution path?

2.

Any ways to “watch” such variables? Currently I am just looking at the asembly code to find what the actual execution is. For example, in source code I pass variable foo to function SetValue, but since in debugger I can not watch such variable foo, then I go to assembly code to watch what values are passed to function SetValue through register or stack.

Any better ideas to debug such x64 optimized code? Is it a common issue in debugging x64 release code?

thanks in advance,
George


You are currently subscribed to windbg as: xxxxx@valhallalegends.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: xxxxx@yahoo.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi mm,

I am reading MSDN topic on DbgHelp, but no information about how PDB is used to match symbol/source code line number with binary. If you have any links, could you post please?

regards,
George

----- Original Message ----
From: Martin O’Brien
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 10:15:08 PM
Subject: Re:[windbg] SPAM-LOW: Re: Debugging issue to watch variable values

Skywing has answered that one already as well - read about DbgEng/DbgHelp in the documentation.

I’m not sure what you’re looking for if you think that is a high level description.

mm

Crispin Wright wrote:
> http://www.codeproject.com/KB/threads/StackWalker.aspx
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Lin George
> Sent: Thursday, September 25, 2008 14:08
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Subject: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values
>
> Thanks Martin!
>
>
> Actually I have read this, but it only covers the format of PDB file in a
> very high level (e.g. into blocks and streams), not mentioned how debugger
> utilizing PDB file to work. Any comments? Do you have any brief description
> of how debugger utilizing PDB file? :slight_smile:
>
> http://www.informit.com/articles/article.aspx?p=22685
>
>
> regards,
> George
>
>
>
> ----- Original Message ----
> From: Martin O’Brien
> To: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 9:02:05 PM
> Subject: Re:[windbg] Debugging issue to watch variable values
>
> I don’t know if it is still published, but ‘Undocumented Windows 2000
> Secrets’ covers part of this. There’s not a whole lot out
> there that discusses this subject.
>
> Good luck,
>
> mm
>
>
>
> Lin George wrote:
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> So you think my issue of watching variables in release x64 mode with
> optimized code is, PDB file has limitation which could not correctly
> reflects the values in registers?
>> 2.
>>
>> I am interested in how debugger could utilize information in PDB file to
> find related symbol related to some binary code. And also how to find
> related source code. I have made quite some search, but few good
> documents/articles. Do you have any of such materials to recommend to read?
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 8:49:28 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> To reiterate what I said earlier, as far as I know, the debug info
> format’s support for locals is based on the assumption that they are stack
> based.
>> This is a limitation of the current tools, and not so much of any
> fundamental technical roadblock aside from the fact that it’s not how things
> were written to work.
>> This is why debug builds always try and put locals on the stack instead of
> exclusively saving them in a register.
>> The .pdb is built at code generation time. Think of it as reflecting a
> view of locals before the optimizer has had a chance to figure out that some
> locals do not need to live on the stack at all, but may reside exclusively
> in a register.
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Thursday, September 25, 2008 01:07
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>>
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> I think PDB is generated at compile/link time, correct?
>>
>>
>> I listed my confusions in 2 and 3, but I do not know which one is correct.
> Any comments?
>> 2.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still not decided, only during runtime will the
> location (whether variable on stack or in register) be decided. – So that
> the generated PDB is not matching the exact situation (e.g. PDB may think
> some variable on stack, but actually it is in register), which cause the
> wrong variable value during debugging?
>> 3.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still be decided, but PDB will completely ignore
> such information in register. – So that the generated PDB is not matching
> the exact situation (e.g. PDB may think some variable on stack, but actually
> it is in register), which cause the wrong variable value during debugging?
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 1:11:17 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> .pdb is the debug file information format which contains symbol and type
> info (including line number mappings) for a binary.
>> As far as I know, the current .pdb formats only describe locals in terms
> of stack locations and not registers. Thus, for locals (including function
> arguments) that get moved into registers, this fact is not recorded in a
> usable way that would allow the debugger to track this.
>> The bottom line is that when you have parameters and locals being moved
> into registers, they will not show correct values in the local variable
> display in the debugger. The only guaranteed reliable way to do it is to
> look at the actual disassembly and figure out what variables are going
> where.
>> - S
>>
>> -----Original Message-----
>> From: Lin George [mailto:xxxxx@yahoo.com]
>> Sent: Thursday, September 25, 2008 12:50 AM
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>> Hi Skywing,
>>
>>
>> 1.
>>
>> My confusion is what is the relationshp between PDB and source code, in
> what mechanisms do PDB and source code establish mapping relationship?
>> 2.
>>
>> “This is because PDB does not allow reliable tracking of variables that
> get cached in registers” – I always think PDB is 100% match binary even if
> optimized code, but seems not?
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Sent: Wednesday, September 24, 2008 9:58:05 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> This is because PDB does not allow reliable tracking of variables that get
> cached in registers.
>> You should be analyzing the code manually in this case.
>>
>> Local variable support is only reliable when you are doing source line
> stepping in a non-optimized debug build.
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Wednesday, September 24, 2008 05:09
>> To: Kernel Debugging Interest List
>> Subject: [windbg] Debugging issue to watch variable values
>>
>>
>> Hello everyone,
>>
>>
>> 1.
>>
>> Sometimes in x64 release code (optimized to full level), even if we
> defined some global data, variables or member variables for some data
> structures, we can not see the actual value in debugger. The related error
> message is – “Error: expression cannot be evaluated”.
>> I think it is because of x64 code optimization to remove some variables or
> changed code execution path?
>> 2.
>>
>> Any ways to “watch” such variables? Currently I am just looking at the
> asembly code to find what the actual execution is. For example, in source
> code I pass variable foo to function SetValue, but since in debugger I can
> not watch such variable foo, then I go to assembly code to watch what values
> are passed to function SetValue through register or stack.
>> Any better ideas to debug such x64 optimized code? Is it a common issue in
> debugging x64 release code?
>>
>> thanks in advance,
>> George
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: xxxxx@valhallalegends.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>
> —
> You are currently subscribed to windbg as: xxxxx@yahoo.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> Information from ESET NOD32 Antivirus, version of virus signature
> database 3471 (20080925)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>


You are currently subscribed to windbg as: xxxxx@yahoo.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Do you have any documents covering how PDB is used to match symbol/source code line number with binary. If you have any links, could you post please?

regards,
George

----- Original Message ----
From: Crispin Wright
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 10:04:36 PM
Subject: RE: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values

http://www.codeproject.com/KB/threads/StackWalker.aspx

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lin George
Sent: Thursday, September 25, 2008 14:08
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Subject: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values

Thanks Martin!

Actually I have read this, but it only covers the format of PDB file in a
very high level (e.g. into blocks and streams), not mentioned how debugger
utilizing PDB file to work. Any comments? Do you have any brief description
of how debugger utilizing PDB file? :slight_smile:

http://www.informit.com/articles/article.aspx?p=22685

regards,
George

----- Original Message ----
From: Martin O’Brien
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:02:05 PM
Subject: Re:[windbg] Debugging issue to watch variable values

I don’t know if it is still published, but ‘Undocumented Windows 2000
Secrets’ covers part of this. There’s not a whole lot out
there that discusses this subject.

Good luck,

mm

Lin George wrote:
> Thanks Skywing,
>
>
> 1.
>
> So you think my issue of watching variables in release x64 mode with
optimized code is, PDB file has limitation which could not correctly
reflects the values in registers?
>
> 2.
>
> I am interested in how debugger could utilize information in PDB file to
find related symbol related to some binary code. And also how to find
related source code. I have made quite some search, but few good
documents/articles. Do you have any of such materials to recommend to read?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Skywing
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 8:49:28 PM
> Subject: RE: [windbg] Debugging issue to watch variable values
>
> To reiterate what I said earlier, as far as I know, the debug info
format’s support for locals is based on the assumption that they are stack
based.
>
> This is a limitation of the current tools, and not so much of any
fundamental technical roadblock aside from the fact that it’s not how things
were written to work.
>
> This is why debug builds always try and put locals on the stack instead of
exclusively saving them in a register.
>
> The .pdb is built at code generation time. Think of it as reflecting a
view of locals before the optimizer has had a chance to figure out that some
locals do not need to live on the stack at all, but may reside exclusively
in a register.
>
> - S
>
> -----Original Message-----
> From: Lin George
> Sent: Thursday, September 25, 2008 01:07
> To: Skywing
> Cc: Kernel Debugging Interest List
> Subject: Re: [windbg] Debugging issue to watch variable values
>
>
> Thanks Skywing,
>
>
> 1.
>
> I think PDB is generated at compile/link time, correct?
>
>
> I listed my confusions in 2 and 3, but I do not know which one is correct.
Any comments?
>
> 2.
>
> If yes to 1, then during compile/link time, whether variable will be put
on stack or in register is still not decided, only during runtime will the
location (whether variable on stack or in register) be decided. – So that
the generated PDB is not matching the exact situation (e.g. PDB may think
some variable on stack, but actually it is in register), which cause the
wrong variable value during debugging?
>
> 3.
>
> If yes to 1, then during compile/link time, whether variable will be put
on stack or in register is still be decided, but PDB will completely ignore
such information in register. – So that the generated PDB is not matching
the exact situation (e.g. PDB may think some variable on stack, but actually
it is in register), which cause the wrong variable value during debugging?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Skywing
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 1:11:17 PM
> Subject: RE: [windbg] Debugging issue to watch variable values
>
> .pdb is the debug file information format which contains symbol and type
info (including line number mappings) for a binary.
>
> As far as I know, the current .pdb formats only describe locals in terms
of stack locations and not registers. Thus, for locals (including function
arguments) that get moved into registers, this fact is not recorded in a
usable way that would allow the debugger to track this.
>
> The bottom line is that when you have parameters and locals being moved
into registers, they will not show correct values in the local variable
display in the debugger. The only guaranteed reliable way to do it is to
look at the actual disassembly and figure out what variables are going
where.
>
> - S
>
> -----Original Message-----
> From: Lin George [mailto:xxxxx@yahoo.com]
> Sent: Thursday, September 25, 2008 12:50 AM
> To: Skywing
> Cc: Kernel Debugging Interest List
> Subject: Re: [windbg] Debugging issue to watch variable values
>
> Hi Skywing,
>
>
> 1.
>
> My confusion is what is the relationshp between PDB and source code, in
what mechanisms do PDB and source code establish mapping relationship?
>
> 2.
>
> “This is because PDB does not allow reliable tracking of variables that
get cached in registers” – I always think PDB is 100% match binary even if
optimized code, but seems not?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Skywing
> To: Kernel Debugging Interest List
> Sent: Wednesday, September 24, 2008 9:58:05 PM
> Subject: RE: [windbg] Debugging issue to watch variable values
>
> This is because PDB does not allow reliable tracking of variables that get
cached in registers.
>
> You should be analyzing the code manually in this case.
>
> Local variable support is only reliable when you are doing source line
stepping in a non-optimized debug build.
>
> - S
>
> -----Original Message-----
> From: Lin George
> Sent: Wednesday, September 24, 2008 05:09
> To: Kernel Debugging Interest List
> Subject: [windbg] Debugging issue to watch variable values
>
>
> Hello everyone,
>
>
> 1.
>
> Sometimes in x64 release code (optimized to full level), even if we
defined some global data, variables or member variables for some data
structures, we can not see the actual value in debugger. The related error
message is – “Error: expression cannot be evaluated”.
>
> I think it is because of x64 code optimization to remove some variables or
changed code execution path?
>
> 2.
>
> Any ways to “watch” such variables? Currently I am just looking at the
asembly code to find what the actual execution is. For example, in source
code I pass variable foo to function SetValue, but since in debugger I can
not watch such variable foo, then I go to assembly code to watch what values
are passed to function SetValue through register or stack.
>
> Any better ideas to debug such x64 optimized code? Is it a common issue in
debugging x64 release code?
>
>
> thanks in advance,
> George
>
>
>
>
> —
> You are currently subscribed to windbg as: xxxxx@valhallalegends.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>


You are currently subscribed to windbg as: xxxxx@yahoo.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Information from ESET NOD32 Antivirus, version of virus signature
database 3471 (20080925)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Think logically. The Microsoft compiler has several modules which accomplish different phases of the compilation. The parser is the first and the optimizer is last, though the linker also does some optimization. In other compilers it might be one program, but it will have multiple passes. An old Borland compiler had a single pass feature but optmization was minimal compared to current versions. The middle compiler modules work with the canned code various statements cause to be generated. Optimizing that code has a tendency to leave the info in the PDB only close to the final code. Unreferenced functions are usually eliminated during the linker run except for static functions.

I have never written a compiler and never want to do so, but some logical thinking about what is provided as input and what is generated should provide a clue. Understanding assembly and how to write in it also helps to understand what’s going on.

“Lin George” wrote in message news:xxxxx@windbg…
Hi Jim,

“the compiler is free to use that register for” – so the optimization of using register is decided at compile/link time, other than runtime? :slight_smile:

regards,
George

----- Original Message ----
From: Jim Donelson
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:28:33 PM
Subject: Re: [windbg] Debugging issue to watch variable values

In a release build with full optimization, it is not possible for the debugger to track a parameter passed in a register, the compiler is free to use that register for something else when that parameter is no longer needed, or to shuffle it to the stack as a temp or another register.

That why optimization is off for a debug build.

On Thu, Sep 25, 2008 at 8:49 AM, Skywing wrote:

To reiterate what I said earlier, as far as I know, the debug info format’s support for locals is based on the assumption that they are stack based.

This is a limitation of the current tools, and not so much of any fundamental technical roadblock aside from the fact that it’s not how things were written to work.

This is why debug builds always try and put locals on the stack instead of exclusively saving them in a register.

The .pdb is built at code generation time. Think of it as reflecting a view of locals before the optimizer has had a chance to figure out that some locals do not need to live on the stack at all, but may reside exclusively in a register.

- S

-----Original Message-----
From: Lin George
Sent: Thursday, September 25, 2008 01:07
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Thanks Skywing,

1.

I think PDB is generated at compile/link time, correct?

I listed my confusions in 2 and 3, but I do not know which one is correct. Any comments?

2.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still not decided, only during runtime will the location (whether variable on stack or in register) be decided. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

3.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still be decided, but PDB will completely ignore such information in register. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 1:11:17 PM
Subject: RE: [windbg] Debugging issue to watch variable values

.pdb is the debug file information format which contains symbol and type info (including line number mappings) for a binary.

As far as I know, the current .pdb formats only describe locals in terms of stack locations and not registers. Thus, for locals (including function arguments) that get moved into registers, this fact is not recorded in a usable way that would allow the debugger to track this.

The bottom line is that when you have parameters and locals being moved into registers, they will not show correct values in the local variable display in the debugger. The only guaranteed reliable way to do it is to look at the actual disassembly and figure out what variables are going where.

- S

-----Original Message-----
From: Lin George [mailto:xxxxx@yahoo.com]
Sent: Thursday, September 25, 2008 12:50 AM
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Hi Skywing,

1.

My confusion is what is the relationshp between PDB and source code, in what mechanisms do PDB and source code establish mapping relationship?

2.

“This is because PDB does not allow reliable tracking of variables that get cached in registers” – I always think PDB is 100% match binary even if optimized code, but seems not?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Sent: Wednesday, September 24, 2008 9:58:05 PM
Subject: RE: [windbg] Debugging issue to watch variable values

This is because PDB does not allow reliable tracking of variables that get cached in registers.

You should be analyzing the code manually in this case.

Local variable support is only reliable when you are doing source line stepping in a non-optimized debug build.

- S

-----Original Message-----
From: Lin George
Sent: Wednesday, September 24, 2008 05:09
To: Kernel Debugging Interest List
Subject: [windbg] Debugging issue to watch variable values

Hello everyone,

1.

Sometimes in x64 release code (optimized to full level), even if we defined some global data, variables or member variables for some data structures, we can not see the actual value in debugger. The related error message is – “Error: expression cannot be evaluated”.

I think it is because of x64 code optimization to remove some variables or changed code execution path?

2.

Any ways to “watch” such variables? Currently I am just looking at the asembly code to find what the actual execution is. For example, in source code I pass variable foo to function SetValue, but since in debugger I can not watch such variable foo, then I go to assembly code to watch what values are passed to function SetValue through register or stack.

Any better ideas to debug such x64 optimized code? Is it a common issue in debugging x64 release code?

thanks in advance,
George


You are currently subscribed to windbg as: xxxxx@valhallalegends.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— You are currently subscribed to windbg as: xxxxx@yahoo.com To unsubscribe send a blank email to xxxxx@lists.osr.com

Become an advanced programmer and go to work for a compiler company. Having
a PhD in Computer Science may help too. Much of this is just magic in how
it is done so quickly. Taking the output assembly from an unoptimized
compile and hand re-coding it for speed and/or size as desired. Then see
how close the original source can be matched with the new assembly. You are
asking for confidential information that no compiler company will provide
though open source compilers can help understand what goes on. Each one
does it their own way or the way someone in the past chose to accomplish
their task.

“Lin George” wrote in message
news:xxxxx@windbg…
> Do you have any documents covering how PDB is used to match symbol/source
> code line number with binary. If you have any links, could you post
> please?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Crispin Wright
> To: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 10:04:36 PM
> Subject: RE: SPAM-LOW: Re: [windbg] Debugging issue to watch variable
> values
>
> http://www.codeproject.com/KB/threads/StackWalker.aspx
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Lin George
> Sent: Thursday, September 25, 2008 14:08
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Subject: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values
>
> Thanks Martin!
>
>
> Actually I have read this, but it only covers the format of PDB file in a
> very high level (e.g. into blocks and streams), not mentioned how debugger
> utilizing PDB file to work. Any comments? Do you have any brief
> description
> of how debugger utilizing PDB file? :slight_smile:
>
> http://www.informit.com/articles/article.aspx?p=22685
>
>
> regards,
> George
>
>
>
> ----- Original Message ----
> From: Martin O’Brien
> To: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 9:02:05 PM
> Subject: Re:[windbg] Debugging issue to watch variable values
>
> I don’t know if it is still published, but ‘Undocumented Windows 2000
> Secrets’ covers part of this. There’s not a whole lot out
> there that discusses this subject.
>
> Good luck,
>
> mm
>
>
>
> Lin George wrote:
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> So you think my issue of watching variables in release x64 mode with
> optimized code is, PDB file has limitation which could not correctly
> reflects the values in registers?
>>
>> 2.
>>
>> I am interested in how debugger could utilize information in PDB file to
> find related symbol related to some binary code. And also how to find
> related source code. I have made quite some search, but few good
> documents/articles. Do you have any of such materials to recommend to
> read?
>>
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 8:49:28 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> To reiterate what I said earlier, as far as I know, the debug info
> format’s support for locals is based on the assumption that they are stack
> based.
>>
>> This is a limitation of the current tools, and not so much of any
> fundamental technical roadblock aside from the fact that it’s not how
> things
> were written to work.
>>
>> This is why debug builds always try and put locals on the stack instead
>> of
> exclusively saving them in a register.
>>
>> The .pdb is built at code generation time. Think of it as reflecting a
> view of locals before the optimizer has had a chance to figure out that
> some
> locals do not need to live on the stack at all, but may reside exclusively
> in a register.
>>
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Thursday, September 25, 2008 01:07
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>>
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> I think PDB is generated at compile/link time, correct?
>>
>>
>> I listed my confusions in 2 and 3, but I do not know which one is
>> correct.
> Any comments?
>>
>> 2.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still not decided, only during runtime will the
> location (whether variable on stack or in register) be decided. – So that
> the generated PDB is not matching the exact situation (e.g. PDB may think
> some variable on stack, but actually it is in register), which cause the
> wrong variable value during debugging?
>>
>> 3.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still be decided, but PDB will completely
> ignore
> such information in register. – So that the generated PDB is not
> matching
> the exact situation (e.g. PDB may think some variable on stack, but
> actually
> it is in register), which cause the wrong variable value during debugging?
>>
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 1:11:17 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> .pdb is the debug file information format which contains symbol and type
> info (including line number mappings) for a binary.
>>
>> As far as I know, the current .pdb formats only describe locals in terms
> of stack locations and not registers. Thus, for locals (including
> function
> arguments) that get moved into registers, this fact is not recorded in a
> usable way that would allow the debugger to track this.
>>
>> The bottom line is that when you have parameters and locals being moved
> into registers, they will not show correct values in the local variable
> display in the debugger. The only guaranteed reliable way to do it is to
> look at the actual disassembly and figure out what variables are going
> where.
>>
>> - S
>>
>> -----Original Message-----
>> From: Lin George [mailto:xxxxx@yahoo.com]
>> Sent: Thursday, September 25, 2008 12:50 AM
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>> Hi Skywing,
>>
>>
>> 1.
>>
>> My confusion is what is the relationshp between PDB and source code, in
> what mechanisms do PDB and source code establish mapping relationship?
>>
>> 2.
>>
>> “This is because PDB does not allow reliable tracking of variables that
> get cached in registers” – I always think PDB is 100% match binary even
> if
> optimized code, but seems not?
>>
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Sent: Wednesday, September 24, 2008 9:58:05 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> This is because PDB does not allow reliable tracking of variables that
>> get
> cached in registers.
>>
>> You should be analyzing the code manually in this case.
>>
>> Local variable support is only reliable when you are doing source line
> stepping in a non-optimized debug build.
>>
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Wednesday, September 24, 2008 05:09
>> To: Kernel Debugging Interest List
>> Subject: [windbg] Debugging issue to watch variable values
>>
>>
>> Hello everyone,
>>
>>
>> 1.
>>
>> Sometimes in x64 release code (optimized to full level), even if we
> defined some global data, variables or member variables for some data
> structures, we can not see the actual value in debugger. The related error
> message is – “Error: expression cannot be evaluated”.
>>
>> I think it is because of x64 code optimization to remove some variables
>> or
> changed code execution path?
>>
>> 2.
>>
>> Any ways to “watch” such variables? Currently I am just looking at the
> asembly code to find what the actual execution is. For example, in source
> code I pass variable foo to function SetValue, but since in debugger I can
> not watch such variable foo, then I go to assembly code to watch what
> values
> are passed to function SetValue through register or stack.
>>
>> Any better ideas to debug such x64 optimized code? Is it a common issue
>> in
> debugging x64 release code?
>>
>>
>> thanks in advance,
>> George
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: xxxxx@valhallalegends.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>
> —
> You are currently subscribed to windbg as: xxxxx@yahoo.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> Information from ESET NOD32 Antivirus, version of virus
> signature
> database 3471 (20080925)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>

Thanks pro,

I also looked into DbgHelp documents about MSDN. But what I really want is some basic theory and approach about how debugger could utilize PDB file to match binary code with source code/symbols/values for symbols. I did search but find no such information. Do you have any recommendations to read? Or links? :slight_smile:

regards,
George

----- Original Message ----
From: Prokash Sinha
To: Lin George
Sent: Friday, September 26, 2008 12:55:48 AM
Subject: Re: [windbg] Debugging issue to watch variable values

A first good place to look at is John Robbins Windows debugging book ( if my memory is not corrupted :frowning: ). That with the DbgHelp interface (as Ski pointed out) would be good thing to look at… that has plentry of infos about pdb etc…

If you search MSDN online, I think there are some good discussion about how the calling conventions stack usages etc works under x64 … I once wrote?an internal memo about how to debug x64 release code ( but unfortunately it is not handy at that moment… need some mining? … to find it ).

Basically you really have no option for symbolic debugging the register maps ( i.e. those symbolic vars being mapped to registers:(1)either at args passing stage; or(2) for local variables. When optimizations are on (due to large register sets) compiler does uses those registers, and current pdb generations don’t provide those as far as I recall/know…

-pro

On Wed, Sep 24, 2008 at 9:52 PM, Lin George wrote:

Thanks?Prokash,

I did some search and want to find how PDB establish relationship with binary (i.e. how bianry is using PDB to resolve symbols), but failed to find any good documents. Do you have any recommendations?

regards,
George

----- Original Message ----
From: Prokash Sinha
To: Kernel Debugging Interest List

Sent: Thursday, September 25, 2008 12:47:12 AM
Subject: Re: [windbg] Debugging issue to watch variable values

If you have no option but to debug release build ( where optimizations are on ), best thing to look at web to find how the registers are being used to pass the variables instead of stack. IIRC, there are some good and precise documents in the web abou it. Once you have that handy it should be bit easier to debug release code ( by looking at the registers’ value being changed …

-pro

On Wed, Sep 24, 2008 at 3:08 AM, Lin George wrote:

Hello everyone,

1.

Sometimes in x64 release code (optimized to full level), even if we defined some global data, variables or member variables for some data structures, we can not see the actual value in debugger. The related error message is – “Error: expression cannot be evaluated”.

I think it is because of x64 code optimization to remove some variables or changed code execution path?

2.

Any ways to “watch” such variables? Currently I am just looking at the asembly code to find what the actual execution is. For example, in source code I pass variable foo to function SetValue, but since in debugger I can not watch such variable foo, then I go to assembly code to watch what values are passed to function SetValue through register or stack.

Any better ideas to debug such x64 optimized code? Is it a common issue in debugging x64 release code?

thanks in advance,
George



You are currently subscribed to windbg as: xxxxx@gmail.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

— You are currently subscribed to windbg as: xxxxx@yahoo.com To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks David,

What points do you want to express? PDB file is reasonble to not reflect optimization (like putting variable into register not in stack) of real final binary code, which causes debugger not able to recognize variable value?

regards,
George

----- Original Message ----
From: David Craig
To: Kernel Debugging Interest List
Sent: Friday, September 26, 2008 2:43:56 PM
Subject: Re:[windbg] Debugging issue to watch variable values

Think logically.? The Microsoft compiler has several modules which accomplish different phases of the compilation.? The parser is the first and the optimizer is last, though the linker also does some optimization.? In other compilers it might be one program, but it will have multiple passes.? An old Borland compiler had a single pass feature but optmization was minimal compared to current versions.? The middle compiler modules work with the canned code various statements cause to be generated.? Optimizing that code has a tendency to leave the info in the PDB only close to the final code.? Unreferenced functions are usually eliminated during the linker run except for static functions.
?
I have never written a compiler and never want to do so, but some logical thinking about what is provided as input and what is generated should provide a clue.? Understanding assembly and how to write in it also helps to understand what’s going on.
?
“Lin George” wrote in message news:xxxxx@windbg…
Hi?Jim,

“the compiler is free to use that register for” – so the optimization of using register is decided at compile/link time, other than runtime? :slight_smile:

regards,
George

----- Original Message ----
From: Jim Donelson
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:28:33 PM
Subject: Re: [windbg] Debugging issue to watch variable values

In a release build with full optimization, it is not possible for the debugger to track a parameter passed in a register, the compiler is free to use that register for something else when that parameter is no longer needed, or to shuffle it to the stack as a temp or another register.

That why optimization is off for a debug build.
?

On Thu, Sep 25, 2008 at 8:49 AM, Skywing wrote:

To reiterate what I said earlier, as far as I know, the debug info format’s support for locals is based on the assumption that they are stack based.

This is a limitation of the current tools, and not so much of any fundamental technical roadblock aside from the fact that it’s not how things were written to work.

This is why debug builds always try and put locals on the stack instead of exclusively saving them in a register.

The .pdb is built at code generation time. ?Think of it as reflecting a view of locals before the optimizer has had a chance to figure out that some locals do not need to live on the stack at all, but may reside exclusively in a register.

- S

-----Original Message-----
From: Lin George
Sent: Thursday, September 25, 2008 01:07
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Thanks Skywing,

1.

I think PDB is generated at compile/link time, correct?

I listed my confusions in 2 and 3, but I do not know which one is correct. Any comments?

2.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still not decided, only during runtime will the location (whether variable on stack or in register) be decided. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

3.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still be decided, but PDB will completely ignore such information in register. ?-- So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 1:11:17 PM
Subject: RE: [windbg] Debugging issue to watch variable values

.pdb is the debug file information format which contains symbol and type info (including line number mappings) for a binary.

As far as I know, the current .pdb formats only describe locals in terms of stack locations and not registers. ?Thus, for locals (including function arguments) that get moved into registers, this fact is not recorded in a usable way that would allow the debugger to track this.

The bottom line is that when you have parameters and locals being moved into registers, they will not show correct values in the local variable display in the debugger. ?The only guaranteed reliable way to do it is to look at the actual disassembly and figure out what variables are going where.

- S

-----Original Message-----
From: Lin George [mailto:xxxxx@yahoo.com]
Sent: Thursday, September 25, 2008 12:50 AM
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Hi Skywing,

1.

My confusion is what is the relationshp between PDB and source code, in what mechanisms do PDB and source code establish mapping relationship?

2.

“This is because PDB does not allow reliable tracking of variables that get cached in registers” – I always think PDB is 100% match binary even if optimized code, but seems not?

regards,
George

----- Original Message ----
From: Skywing
To: Kernel Debugging Interest List
Sent: Wednesday, September 24, 2008 9:58:05 PM
Subject: RE: [windbg] Debugging issue to watch variable values

This is because PDB does not allow reliable tracking of variables that get cached in registers.

You should be analyzing the code manually in this case.

Local variable support is only reliable when you are doing source line stepping in a non-optimized debug build.

- S

-----Original Message-----
From: Lin George
Sent: Wednesday, September 24, 2008 05:09
To: Kernel Debugging Interest List
Subject: [windbg] Debugging issue to watch variable values

Hello everyone,

1.

Sometimes in x64 release code (optimized to full level), even if we defined some global data, variables or member variables for some data structures, we can not see the actual value in debugger. The related error message is – “Error: expression cannot be evaluated”.

I think it is because of x64 code optimization to remove some variables or changed code execution path?

2.

Any ways to “watch” such variables? Currently I am just looking at the asembly code to find what the actual execution is. For example, in source code I pass variable foo to function SetValue, but since in debugger I can not watch such variable foo, then I go to assembly code to watch what values are passed to function SetValue through register or stack.

Any better ideas to debug such x64 optimized code? Is it a common issue in debugging x64 release code?

thanks in advance,
George


You are currently subscribed to windbg as: xxxxx@valhallalegends.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— You are currently subscribed to windbg as: xxxxx@yahoo.com To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Sorry, David.

I do not know it is confidential information about how debugger will use PDB. Actuallty I do not want to know the exact information in details, like the data structures for PDB or something, but rather some general theory of how compiler will utilize PDB. For such level of documents, do you have any recommendations to read? :slight_smile:

regards,
George

----- Original Message ----
From: David Craig
To: Kernel Debugging Interest List
Sent: Friday, September 26, 2008 2:48:01 PM
Subject: Re:[windbg] SPAM-LOW: Re: Debugging issue to watch variable values

Become an advanced programmer and go to work for a compiler company.? Having
a PhD in Computer Science may help too.? Much of this is just magic in how
it is done so quickly.? Taking the output assembly from an unoptimized
compile and hand re-coding it for speed and/or size as desired.? Then see
how close the original source can be matched with the new assembly.? You are
asking for confidential information that no compiler company will provide
though open source compilers can help understand what goes on.? Each one
does it their own way or the way someone in the past chose to accomplish
their task.

“Lin George” wrote in message
news:xxxxx@windbg…
> Do you have any documents covering how PDB is used to match symbol/source
> code line number with binary. If you have any links, could you post
> please?
>
>
> regards,
> George
>
>
> ----- Original Message ----
> From: Crispin Wright
> To: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 10:04:36 PM
> Subject: RE: SPAM-LOW:? Re: [windbg] Debugging issue to watch variable
> values
>
> http://www.codeproject.com/KB/threads/StackWalker.aspx
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Lin George
> Sent: Thursday, September 25, 2008 14:08
> To: Kernel Debugging Interest List
> Cc: Kernel Debugging Interest List
> Subject: SPAM-LOW: Re: [windbg] Debugging issue to watch variable values
>
> Thanks Martin!
>
>
> Actually I have read this, but it only covers the format of PDB file in a
> very high level (e.g. into blocks and streams), not mentioned how debugger
> utilizing PDB file to work. Any comments? Do you have any brief
> description
> of how debugger utilizing PDB file? :slight_smile:
>
> http://www.informit.com/articles/article.aspx?p=22685
>
>
> regards,
> George
>
>
>
> ----- Original Message ----
> From: Martin O’Brien
> To: Kernel Debugging Interest List
> Sent: Thursday, September 25, 2008 9:02:05 PM
> Subject: Re:[windbg] Debugging issue to watch variable values
>
> I don’t know if it is still published, but ‘Undocumented Windows 2000
> Secrets’ covers part of this.? There’s not a whole lot out
> there that discusses this subject.
>
> Good luck,
>
> mm
>
>
>
> Lin George wrote:
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> So you think my issue of watching variables in release x64 mode with
> optimized code is, PDB file has limitation which could not correctly
> reflects the values in registers?
>>
>> 2.
>>
>> I am interested in how debugger could utilize information in PDB file to
> find related symbol related to some binary code. And also how to find
> related source code. I have made quite some search, but few good
> documents/articles. Do you have any of such materials to recommend to
> read?
>>
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 8:49:28 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> To reiterate what I said earlier, as far as I know, the debug info
> format’s support for locals is based on the assumption that they are stack
> based.
>>
>> This is a limitation of the current tools, and not so much of any
> fundamental technical roadblock aside from the fact that it’s not how
> things
> were written to work.
>>
>> This is why debug builds always try and put locals on the stack instead
>> of
> exclusively saving them in a register.
>>
>> The .pdb is built at code generation time.? Think of it as reflecting a
> view of locals before the optimizer has had a chance to figure out that
> some
> locals do not need to live on the stack at all, but may reside exclusively
> in a register.
>>
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Thursday, September 25, 2008 01:07
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>>
>> Thanks Skywing,
>>
>>
>> 1.
>>
>> I think PDB is generated at compile/link time, correct?
>>
>>
>> I listed my confusions in 2 and 3, but I do not know which one is
>> correct.
> Any comments?
>>
>> 2.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still not decided, only during runtime will the
> location (whether variable on stack or in register) be decided. – So that
> the generated PDB is not matching the exact situation (e.g. PDB may think
> some variable on stack, but actually it is in register), which cause the
> wrong variable value during debugging?
>>
>> 3.
>>
>> If yes to 1, then during compile/link time, whether variable will be put
> on stack or in register is still be decided, but PDB will completely
> ignore
> such information in register.? – So that the generated PDB is not
> matching
> the exact situation (e.g. PDB may think some variable on stack, but
> actually
> it is in register), which cause the wrong variable value during debugging?
>>
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Cc: Kernel Debugging Interest List
>> Sent: Thursday, September 25, 2008 1:11:17 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> .pdb is the debug file information format which contains symbol and type
> info (including line number mappings) for a binary.
>>
>> As far as I know, the current .pdb formats only describe locals in terms
> of stack locations and not registers.? Thus, for locals (including
> function
> arguments) that get moved into registers, this fact is not recorded in a
> usable way that would allow the debugger to track this.
>>
>> The bottom line is that when you have parameters and locals being moved
> into registers, they will not show correct values in the local variable
> display in the debugger.? The only guaranteed reliable way to do it is to
> look at the actual disassembly and figure out what variables are going
> where.
>>
>> - S
>>
>> -----Original Message-----
>> From: Lin George [mailto:xxxxx@yahoo.com]
>> Sent: Thursday, September 25, 2008 12:50 AM
>> To: Skywing
>> Cc: Kernel Debugging Interest List
>> Subject: Re: [windbg] Debugging issue to watch variable values
>>
>> Hi Skywing,
>>
>>
>> 1.
>>
>> My confusion is what is the relationshp between PDB and source code, in
> what mechanisms do PDB and source code establish mapping relationship?
>>
>> 2.
>>
>> “This is because PDB does not allow reliable tracking of variables that
> get cached in registers” – I always think PDB is 100% match binary even
> if
> optimized code, but seems not?
>>
>>
>> regards,
>> George
>>
>>
>> ----- Original Message ----
>> From: Skywing
>> To: Kernel Debugging Interest List
>> Sent: Wednesday, September 24, 2008 9:58:05 PM
>> Subject: RE: [windbg] Debugging issue to watch variable values
>>
>> This is because PDB does not allow reliable tracking of variables that
>> get
> cached in registers.
>>
>> You should be analyzing the code manually in this case.
>>
>> Local variable support is only reliable when you are doing source line
> stepping in a non-optimized debug build.
>>
>> - S
>>
>> -----Original Message-----
>> From: Lin George
>> Sent: Wednesday, September 24, 2008 05:09
>> To: Kernel Debugging Interest List
>> Subject: [windbg] Debugging issue to watch variable values
>>
>>
>> Hello everyone,
>>
>>
>> 1.
>>
>> Sometimes in x64 release code (optimized to full level), even if we
> defined some global data, variables or member variables for some data
> structures, we can not see the actual value in debugger. The related error
> message is – “Error: expression cannot be evaluated”.
>>
>> I think it is because of x64 code optimization to remove some variables
>> or
> changed code execution path?
>>
>> 2.
>>
>> Any ways to “watch” such variables? Currently I am just looking at the
> asembly code to find what the actual execution is. For example, in source
> code I pass variable foo to function SetValue, but since in debugger I can
> not watch such variable foo, then I go to assembly code to watch what
> values
> are passed to function SetValue through register or stack.
>>
>> Any better ideas to debug such x64 optimized code? Is it a common issue
>> in
> debugging x64 release code?
>>
>>
>> thanks in advance,
>> George
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: xxxxx@valhallalegends.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>> —
>> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>
> —
> You are currently subscribed to windbg as: xxxxx@yahoo.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> Information from ESET NOD32 Antivirus, version of virus
> signature
> database 3471 (20080925)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> —
> You are currently subscribed to windbg as: unknown lmsubst tag argument:
> ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>


You are currently subscribed to windbg as: xxxxx@yahoo.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Yes, for statically compiled languages, this is a build-time decision.

  • S

From: Lin George
Sent: Friday, September 26, 2008 01:20
To: Kernel Debugging Interest List
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Hi Jim,

“the compiler is free to use that register for” – so the optimization of using register is decided at compile/link time, other than runtime? :slight_smile:

regards,
George

----- Original Message ----
From: Jim Donelson
To: Kernel Debugging Interest List
Sent: Thursday, September 25, 2008 9:28:33 PM
Subject: Re: [windbg] Debugging issue to watch variable values

In a release build with full optimization, it is not possible for the debugger to track a parameter passed in a register, the compiler is free to use that register for something else when that parameter is no longer needed, or to shuffle it to the stack as a temp or another register.

That why optimization is off for a debug build.

On Thu, Sep 25, 2008 at 8:49 AM, Skywing > wrote:
To reiterate what I said earlier, as far as I know, the debug info format’s support for locals is based on the assumption that they are stack based.

This is a limitation of the current tools, and not so much of any fundamental technical roadblock aside from the fact that it’s not how things were written to work.

This is why debug builds always try and put locals on the stack instead of exclusively saving them in a register.

The .pdb is built at code generation time. Think of it as reflecting a view of locals before the optimizer has had a chance to figure out that some locals do not need to live on the stack at all, but may reside exclusively in a register.

- S

-----Original Message-----
From: Lin George >
Sent: Thursday, September 25, 2008 01:07
To: Skywing >
Cc: Kernel Debugging Interest List >
Subject: Re: [windbg] Debugging issue to watch variable values

Thanks Skywing,

1.

I think PDB is generated at compile/link time, correct?

I listed my confusions in 2 and 3, but I do not know which one is correct. Any comments?

2.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still not decided, only during runtime will the location (whether variable on stack or in register) be decided. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

3.

If yes to 1, then during compile/link time, whether variable will be put on stack or in register is still be decided, but PDB will completely ignore such information in register. – So that the generated PDB is not matching the exact situation (e.g. PDB may think some variable on stack, but actually it is in register), which cause the wrong variable value during debugging?

regards,
George

----- Original Message ----
From: Skywing >
To: Kernel Debugging Interest List >
Cc: Kernel Debugging Interest List >
Sent: Thursday, September 25, 2008 1:11:17 PM
Subject: RE: [windbg] Debugging issue to watch variable values

.pdb is the debug file information format which contains symbol and type info (including line number mappings) for a binary.

As far as I know, the current .pdb formats only describe locals in terms of stack locations and not registers. Thus, for locals (including function arguments) that get moved into registers, this fact is not recorded in a usable way that would allow the debugger to track this.

The bottom line is that when you have parameters and locals being moved into registers, they will not show correct values in the local variable display in the debugger. The only guaranteed reliable way to do it is to look at the actual disassembly and figure out what variables are going where.

- S

-----Original Message-----
From: Lin George [mailto:xxxxx@yahoo.commailto:xxxxx]
Sent: Thursday, September 25, 2008 12:50 AM
To: Skywing
Cc: Kernel Debugging Interest List
Subject: Re: [windbg] Debugging issue to watch variable values

Hi Skywing,

1.

My confusion is what is the relationshp between PDB and source code, in what mechanisms do PDB and source code establish mapping relationship?

2.

“This is because PDB does not allow reliable tracking of variables that get cached in registers” – I always think PDB is 100% match binary even if optimized code, but seems not?

regards,
George

----- Original Message ----
From: Skywing >
To: Kernel Debugging Interest List >
Sent: Wednesday, September 24, 2008 9:58:05 PM
Subject: RE: [windbg] Debugging issue to watch variable values

This is because PDB does not allow reliable tracking of variables that get cached in registers.

You should be analyzing the code manually in this case.

Local variable support is only reliable when you are doing source line stepping in a non-optimized debug build.

- S

-----Original Message-----
From: Lin George >
Sent: Wednesday, September 24, 2008 05:09
To: Kernel Debugging Interest List >
Subject: [windbg] Debugging issue to watch variable values

Hello everyone,

1.

Sometimes in x64 release code (optimized to full level), even if we defined some global data, variables or member variables for some data structures, we can not see the actual value in debugger. The related error message is – “Error: expression cannot be evaluated”.

I think it is because of x64 code optimization to remove some variables or changed code execution path?

2.

Any ways to “watch” such variables? Currently I am just looking at the asembly code to find what the actual execution is. For example, in source code I pass variable foo to function SetValue, but since in debugger I can not watch such variable foo, then I go to assembly code to watch what values are passed to function SetValue through register or stack.

Any better ideas to debug such x64 optimized code? Is it a common issue in debugging x64 release code?

thanks in advance,
George


You are currently subscribed to windbg as: xxxxx@valhallalegends.commailto:xxxxx
To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx

— You are currently subscribed to windbg as: xxxxx@yahoo.com To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to windbg as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Lin George wrote:

I also looked into DbgHelp documents about MSDN. But what I really
want is some basic theory and approach about how debugger could
utilize PDB file to match binary code with source code/symbols/values
for symbols. I did search but find no such information. Do you have
any recommendations to read? Or links? :slight_smile:

George, this is a perfect example of the kind of questions from you that
drive people nuts on the microsoft.public newsgroups… :wink:

What possible good would this knowledge do you? Assuming you could find
an answer, would it allow you to write better programs? No. This
information is only of use to compiler developers and debugger
developers. Therefore, what is the point in learning it? There are so
many things you COULD be drilling into that WOULD make you a better
programmer, it is pointless to waste your time (and ours, as it happens)
delving so deeply into arcane trivia like this.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Glad to know I am not the only one going nuts from him.
:–)

On Fri, Sep 26, 2008 at 1:28 PM, Tim Roberts wrote:

> Lin George wrote:
> >
> > I also looked into DbgHelp documents about MSDN. But what I really
> > want is some basic theory and approach about how debugger could
> > utilize PDB file to match binary code with source code/symbols/values
> > for symbols. I did search but find no such information. Do you have
> > any recommendations to read? Or links? :slight_smile:
>
> George, this is a perfect example of the kind of questions from you that
> drive people nuts on the microsoft.public newsgroups… :wink:
>
> What possible good would this knowledge do you? Assuming you could find
> an answer, would it allow you to write better programs? No. This
> information is only of use to compiler developers and debugger
> developers. Therefore, what is the point in learning it? There are so
> many things you COULD be drilling into that WOULD make you a better
> programmer, it is pointless to waste your time (and ours, as it happens)
> delving so deeply into arcane trivia like this.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> You are currently subscribed to windbg as: xxxxx@jimdonelson.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

+1, but I’m not sure that George sees it the same way as we do, so here’s my final attempt.

  1. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  2. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  3. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  4. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  5. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  6. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  7. IN ORDER TO SUPPORT SYMBOLIC DEBUGGING, WINDBG USES THE INTERFACES PROVIDED BY DBGENG/DBGHELP TO ACCESS THE SYMBOL AND TYPE
    INFORMATION CONTAINED IN A PDB.

  8. The expressions ‘basic theory’ and ‘pdb’ don’t in practice coexist very well. There’s basic theory about how debuggers in
    general use symbols in general, but as soon as you start talking about ‘PDB,’ it’s now quite specific, entirely MSFT and totally
    undocumented. That being said, there are a pretty good number of

Tim Roberts wrote:

Lin George wrote:
>
> I also looked into DbgHelp documents about MSDN. But what I really
> want is some basic theory and approach about how debugger could
> utilize PDB file to match binary code with source code/symbols/values
> for symbols. I did search but find no such information. Do you have
> any recommendations to read? Or links? :slight_smile:

George, this is a perfect example of the kind of questions from you that
drive people nuts on the microsoft.public newsgroups… :wink:

What possible good would this knowledge do you? Assuming you could find
an answer, would it allow you to write better programs? No. This
information is only of use to compiler developers and debugger
developers. Therefore, what is the point in learning it? There are so
many things you COULD be drilling into that WOULD make you a better
programmer, it is pointless to waste your time (and ours, as it happens)
delving so deeply into arcane trivia like this.