Electronics > Microcontrollers

Debugging Hi-Tech C

(1/2) > >>

icon:
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!

IanB:

--- Quote from: icon on April 29, 2012, 06:46:21 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.
--- End quote ---

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.

icon:

--- Quote from: IanB on April 29, 2012, 07:02:11 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.

--- End quote ---

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

IanB:
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?


Rufus:

--- Quote from: icon on April 29, 2012, 07:23:08 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.
--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod