Author Topic: Debugging Hi-Tech C  (Read 5846 times)

0 Members and 1 Guest are viewing this topic.

Offline iconTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Debugging Hi-Tech C
« on: April 29, 2012, 06:46:21 pm »
Hi

Fresh from my battles with this compiler (https://www.eevblog.com/forum/microcontrollers/pichitech-c-conversion-of-char-to-boolean-(bit)/) I'm seeking a bit of advice about the best way of debugging code.

In assembler, I'm accustomed to using MPSIM and simulating the hell out of it. I step through the code, watching registers, poking bits when appropriate, and generally making sure it works. In C I've resorted to writing values and bits to spare ports, using LEDs (or an oscilloscope!) to read them, and stepping through the generated ASM code trying to work out what it's doing.[0] The trouble with the latter is it's a) undocumented, b) written by a machine and c) uses hex values instead of symbols.

Am I missing some obvious higher level debugging option? Where's the C equivalent of the register watch?

Cheers
John

.[0] I only just found out that if the Disassembly Listing is focussed, it steps through an ASM line at a time, whereas if the C listing is focussed it steps one whole line of C code - which was damned unhelpful!
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11858
  • Country: us
Re: Debugging Hi-Tech C
« Reply #1 on: April 29, 2012, 07:02:11 pm »
In assembler, I'm accustomed to using MPSIM and simulating the hell out of it. I step through the code, watching registers, poking bits when appropriate, and generally making sure it works.

This is normally what you do in C as well. I'm not familiar with the particular compiler and tool chain you are using, but normally you would step through the code line by line (either in a simulated environment, or on the actual hardware), examining variables as you go and checking that each line of code and each branch generates the result you expect.

Sometimes you may need to break a complex expression down into several lines so that you can see intermediate results.

With good tools you can switch to a machine code view that shows your code disassembled in an assembly window with program symbols displayed.

The C equivalent of the register watch should be there. Either as a watch window with key variables in it, or a view onto the actual CPU registers to complement the machine code assembly view.
 

Offline iconTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Re: Debugging Hi-Tech C
« Reply #2 on: April 29, 2012, 07:23:08 pm »
The C equivalent of the register watch should be there. Either as a watch window with key variables in it, or a view onto the actual CPU registers to complement the machine code assembly view.

That's the bit I can't find. I can see the PIC's registers, of course, but then I have to plough through the disassembly, to puzzle out where it's putting my variables. I tried sticking a 'printf()' in, to see where it would direct the output - sadly compilation fails with a 'conflicting declarations' error message, which is... sub-optimal.

John
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11858
  • Country: us
Re: Debugging Hi-Tech C
« Reply #3 on: April 29, 2012, 07:42:14 pm »
You may already be familiar with this in general, but this is the kind of thing you would be expecting to see. (In this case with Microsoft Visual Studio.)

Maybe someone here who is familiar with Hi-Tech C can help you?


« Last Edit: April 29, 2012, 07:44:06 pm by IanB »
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Debugging Hi-Tech C
« Reply #4 on: April 29, 2012, 08:02:03 pm »
That's the bit I can't find. I can see the PIC's registers, of course, but then I have to plough through the disassembly, to puzzle out where it's putting my variables.

If you are using MPLAB you have a watch window which will display any global variables you select and a local window automatically displaying all function local variables.

You need to build with debug options set so the compiler generates debug information.
 

Offline iconTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Re: Debugging Hi-Tech C
« Reply #5 on: April 29, 2012, 08:06:51 pm »
Ah - there is a 'Locals' option in the 'View' Menu, with Address, Symbol Name and Value headings. Sounds ideal! Sadly I can't see any way of populating it. No drop-down, can't type anything, 'Properties' dialog box all greyed out.

Anyone?

[Edit to add:]

I've changed from 'release' to 'debug', but still no 'Locals' available. The Watch window allows you to pick SFRs and 'Symbols' - but these latter aren't my program variables, they're internal compiler gubbins. Still missing some compiler build option?

John
« Last Edit: April 29, 2012, 08:19:47 pm by icon »
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Debugging Hi-Tech C
« Reply #6 on: April 29, 2012, 08:10:54 pm »
Ah - there is a 'Locals' option in the 'View' Menu, with Address, Symbol Name and Value headings. Sounds ideal! Sadly I can't see any way of populating it.

Local variables only exist while executing (or stepping through) the functions that contain them. They appear automatically in the local window.
 

Offline iconTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Re: Debugging Hi-Tech C
« Reply #7 on: April 29, 2012, 08:26:13 pm »
Bingo - If I add the mysteriously named symbols in the Watch window ('bitvars2, bitvars3'), my variables are buried underneath those.

Thanks
John
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Debugging Hi-Tech C
« Reply #8 on: April 30, 2012, 03:15:46 pm »
Bingo - If I add the mysteriously named symbols in the Watch window ('bitvars2, bitvars3'), my variables are buried underneath those.

In the watch window the edit control next to the 'Add Symbol' button is a drop down list which also has search as you type functionality.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf