How to identify a condition in debugger

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to identify a condition in debugger

Jump to solution
602 Views
rahulkrishna
Contributor IV

i am using s12x code warrior. My problem is one of the variable value is suddenly going to 0 at some instances, but i am not writing 0 to that variable except for global initialization. Now my  doubt is  using the debugger and using trigger address settings or some other way can I know exactly when that particular variable is becoming 0? I do not how to use the trigger address settings in debugger. Please help.

Labels (1)
1 Solution
490 Views
kef2
Senior Contributor IV

S12X breakpoint HW can catch R/W, R or W access to specific 8 or 16bit location, a) with value on data bus compare, b) without data bus compare, c) address range compare without data bus compare. It is not enough to say that you want to catch write of 0 to any variable. Size of variable matters, since word write to short variable at once and separate writes to higher half and lower half of the same short variable are not the same, trigger setup is different. It is easy to catch W=0 to char variable. You need to do that with S12X core, then with XGATE (if you are using it). For short variable you should try word  write access, then two byte accesses to upper and lower halves. Long variables are even more complicated. And having XGATE running, you have 2x times more work.

Watchpoints. These are the most easy, especially with single core app, but looks like there's an bug in debugger. Value compare sometimes work, sometimes doesn't. It may get triggered once and won't get triggered 2nd time, I don't know why. Watchpoint without data compare work well, but only for single core app. To set watchpoint, you right click on variable in Data Window and click Set Watchpoint. Then to restring stop on watchpoint to W only, you right click in Data Window and click Show Watchpoints..., where you edit your watchpoint settitngs. It's pity that in order to specify core, you need to use 'L vs 'X address notation. It doesn't matter what you see in upper left corner of Data window, HC12 or XGATE,  watchpoints are added with 'L or 'X depending on how variable is defined. To switch to different core you need to determine corresponding logical or XGATE address and use it to make watchpoint active for CPU12X data bus accesses or XGATE accesses.

Triggers. These are more advanced and are easier to switch between cores. The same like with watchpoint, right click on variable in Data window and Set Trigger X address.. A and C triggers allow data bus compare, B and D only address compare. So use just A and C triggers to chase var=0 writes. Then right click again and click Open Trigger Settings Dialog to specify values to compare etc.. "Compare to:" field is value to compare and "With mask:" is bit mask that allows ignoring specific bits. 1 bit in mask means compare, 0 - ignore. Looks like there's an bug in debugger. Word access data compare seems being fine for both word aligned and misaligned word accesses, but byte access data compare seems comparing wrong byte half. To compare char variable for equality with 0xAA, write 0xAA00 to "Compare to:" and 0xFF00 to "With mask:". Perhaps not many people are using triggers, else it would be fixed long time ago? I think I have all CW5.1 patches applied, perhaps not. Perhaps the problem is in maskset of S12XD on my DEMO9S12XDT512. 

There's another plan to try. Try looking at Debug Module documentation. You may set up breakpoints from your code writing required settings directly to Debug Module registers.

Hope this helps
Edward

View solution in original post

2 Replies
491 Views
kef2
Senior Contributor IV

S12X breakpoint HW can catch R/W, R or W access to specific 8 or 16bit location, a) with value on data bus compare, b) without data bus compare, c) address range compare without data bus compare. It is not enough to say that you want to catch write of 0 to any variable. Size of variable matters, since word write to short variable at once and separate writes to higher half and lower half of the same short variable are not the same, trigger setup is different. It is easy to catch W=0 to char variable. You need to do that with S12X core, then with XGATE (if you are using it). For short variable you should try word  write access, then two byte accesses to upper and lower halves. Long variables are even more complicated. And having XGATE running, you have 2x times more work.

Watchpoints. These are the most easy, especially with single core app, but looks like there's an bug in debugger. Value compare sometimes work, sometimes doesn't. It may get triggered once and won't get triggered 2nd time, I don't know why. Watchpoint without data compare work well, but only for single core app. To set watchpoint, you right click on variable in Data Window and click Set Watchpoint. Then to restring stop on watchpoint to W only, you right click in Data Window and click Show Watchpoints..., where you edit your watchpoint settitngs. It's pity that in order to specify core, you need to use 'L vs 'X address notation. It doesn't matter what you see in upper left corner of Data window, HC12 or XGATE,  watchpoints are added with 'L or 'X depending on how variable is defined. To switch to different core you need to determine corresponding logical or XGATE address and use it to make watchpoint active for CPU12X data bus accesses or XGATE accesses.

Triggers. These are more advanced and are easier to switch between cores. The same like with watchpoint, right click on variable in Data window and Set Trigger X address.. A and C triggers allow data bus compare, B and D only address compare. So use just A and C triggers to chase var=0 writes. Then right click again and click Open Trigger Settings Dialog to specify values to compare etc.. "Compare to:" field is value to compare and "With mask:" is bit mask that allows ignoring specific bits. 1 bit in mask means compare, 0 - ignore. Looks like there's an bug in debugger. Word access data compare seems being fine for both word aligned and misaligned word accesses, but byte access data compare seems comparing wrong byte half. To compare char variable for equality with 0xAA, write 0xAA00 to "Compare to:" and 0xFF00 to "With mask:". Perhaps not many people are using triggers, else it would be fixed long time ago? I think I have all CW5.1 patches applied, perhaps not. Perhaps the problem is in maskset of S12XD on my DEMO9S12XDT512. 

There's another plan to try. Try looking at Debug Module documentation. You may set up breakpoints from your code writing required settings directly to Debug Module registers.

Hope this helps
Edward

489 Views
rahulkrishna
Contributor IV

Surely it helped. Thank you very much for the time, I used the trigger Address settings.

0 Kudos