Author Topic: Debuging webinterface.c in Cw 6.3 Lite  (Read 21015 times)

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Debuging webinterface.c in Cw 6.3 Lite
« on: October 03, 2007, 03:42:44 PM »
 I'm trying to set a breakpoint in fnInsertStrings() to debug my ADC web page that
returns the 8 channels of ADC raw values etc. The code gets executed because I see the
dynamic values displayed on the web page, but the break point I set gets ignored. I can set break points in my adc.c function that handles reading the ADC every 1 sec.


 Thanks,
 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #1 on: October 03, 2007, 04:21:22 PM »
Hi John

If possible I advise using the uTasker simulator for debugging the web interface - even if the ADC values are dummy values you can quite easily debug the parts involved with displaying them.

As your question refers to the SW6.3, where you can debug in one function but not in the other I suspect that it is due to teh optimisation level. This is set to maximum in the normal case and sometimes it can be quite difficult to set a break point which is actually triggered on in the C-code. If you can manage to get it to break somewhere near to where you want it and look at the assembler code it executes it can be surprising how it jumps around - putting break points in the assembler code is a method or getting it to reliably stop there.

Generally it is easiest to turn the level of optimisation down as low as possible and then you should be able to easily break and step in the C-code.

However, as I said at the beginning, web interface debugging works very well in the simulator and is the preferred method in most cases.

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #2 on: October 03, 2007, 06:21:54 PM »
Hi Mark, I tried running the project in the simulator, but I get the
following error when I build it :

 .....\utasker\applications\utaskerv1.3\webinterface.c(24) : fatal error C1083: Cannot open include file: 'mcf5223_adc.h': No such file or directory

  'mcf5223_adc.h' is a file I added in CW in the Hardare folder. I tried adding it to the VC Header Files folder with Add|Existing item and I see it in the VC browser, but I still get the error.

The project builds OK under CW.



 Is it possible to pass more than 4 chars with the £xyz tags ? With our app we may run out of chars if we can't. I started looking in http.c etc


 Thanks,
 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #3 on: October 03, 2007, 08:13:34 PM »
Hi John

Assuming you have the file mcf5223_adc.h located in the hardware directory, there are two possibilities which I would consider.

1. Add #include "mcf5223_adc.h" in hardware.h
This will however mean that if the file hardware.h is updated with a SP you will have to add the line again.

2. Add #include "..\..\hardware\mcf5223_adc.h" in application.h
Assuming that your project directory is not \Applications\uTaskerV1.3 then this file will never be overwritten during an SP update.

The result is that all files will be able to use the contents of your file mcf5223_adc.h.

Probably adding the file to the CW project added its location also in the serach path (?) so that it could be found. The above solution will also work for CW.



The insert parsing always expects 2 values after the parsing type. The lines which determine this in http.c are (around line 800):

            ptrBuffer += 2;                                              // jump over parameters
            usLen -= 3;

this means that the length could be increased in an emergency (but the html file should always have include this length).
However I wouldn't usually expect this to be required, since each of the values can take on any value. If you use 1,2,...9 and a,b,...z, and A,B,C...Z you have 62 possibilities of 'normal' text characters.
The complete combination possibilities is thus easily 62*62 = 3'844 different values which can be quite easily inserted.

Generally the first will identify a block of values and the second a specific value within the block, which will almost certainly reduce the total since blocks will tend to be under-utilised (if they don't have 62 members) but generally makes for easier grouping in the code.

Do you require more that this amount of individual values or blocks of values?

Regards

Mark


Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #4 on: October 03, 2007, 08:45:24 PM »
Hi Mark, I did get around the error in VC by including the relative path
to mcf5223_adc.h in config.h, but I then get the following link errors :

application.obj : error LNK2019: unresolved external symbol _fnSendSNMPTrap referenced in function _fnApplication
application.obj : error LNK2019: unresolved external symbol _fnStartSNMP referenced in function _fnApplication
webInterface.obj : error LNK2001: unresolved external symbol _ADC_Chans
M5223X.obj : error LNK2019: unresolved external symbol _fnInit_adc referenced in function _fnInitHW
WinSim.obj : error LNK2001: unresolved external symbol _fnADC
WinSim.obj : error LNK2001: unresolved external symbol _fnSNMP
.\Debug/uTaskerV1-3.exe : fatal error LNK1120: 6 unresolved externals

 I moved the include of mcf5223_adc.h to application.h like you suggested and get the same errors. I specify the following prototypes in mcf5223_adc.h  so I'm not sure why the VC linker is complaining. config.h includes application.h which includes mcf5223_adc.h, so it should be included in all source files, right ?
fnADC is defined in TaskCOnfig.h and is the ADC task handler that gets called every 1 sec in the app.

    mcf5223_adc.h snippet
     .
     .
////////////////////
//   Prototypes
////////////////////

extern void fnInit_adc (void);
extern ADC_Chan ADC_Chans[];
void fnIniInputs(void);


 Our ADC web page will display the values and programming for
8 input channels. We will have columns for dynamic values for
value, max, min etc and programmed values for Input type, Alram Hi and Low limits etc. I will use a drop down box where the user
can select 1 of maybe 15 values for each input types so I figured that
I would need something like

// System defined
 £  - escape lead in
 W - used for lead in type

 // user defined
 X - Input type
 Y - Channel number (1..8)
 Z - Type (TempC, TempF etc)

 I'm assuming the first 2 chars are reserved for the system and the
last 2 are user definable.


 Thanks,
 John




Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #5 on: October 03, 2007, 09:08:51 PM »
Hi Mark, when I disable optimization ,the code size grows to 124K, so
it doesn't fit in the current flash setup. When I set it to level 1
it does fit ,but I still can't set a C level break point in webinterface.c
I did set a C break point in http.c and steped into the webinterface
fnInsertValue() , but it only allows assembly level debugging :(


 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #6 on: October 03, 2007, 09:19:12 PM »
Hi John

The errors look like you need to add snmp.c and your task file (containing fnADC and ADC_Chans) to the VisualStudio project and then it should work.


The parser interprets the following values of £ and W as defined in config.h. You can change them if needed - for example sometimes the sign £ causes problems when sending it in emails - it somehow gets dropped from the file (???) and so some people prefer to use a different parsing identifier.

Code: [Select]
            #define WEB_PARSER_START          '£'                        // This symbol is used in Web pages to instruct parsing to begin
            #define WEB_INSERT_STRING         'v'
            #define WEB_DISABLE_FIELD         'D'
            #define WEB_NOT_DISABLE_FIELD     'd'
            #define WEB_SELECTED_FIELD        's'
            #define WEB_INSERT_DYNAMIC        'H'

'v' is generally used for insertion of values.
If you prefer to code it into three groups, try changing the values indicated in the last post - I have never tried it but I expect that it will work. You will have to ensure that all use in the project HTML file then follows the same rules - add a padding byte to make all 5 bytes long.
You will however have to also check the following routine in webutils.c.
fnInsertHTMLString() is the magic routine which actually puts the strings prepared by the application into the TCP frames. It is not as simple as it seems... In this routine the escape sequence is replaced by the string and it assumes that the escape sequence is 4 bytes long. I expect that replaceing the 4 by 5 at every occurence will solve it too. Probably best set a define instead so that it can be changed back easily if something goes wrong!

Good luck

Regards

Mark


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #7 on: October 03, 2007, 09:23:44 PM »
Hi John

If you need to debug on the target you may be able to remove some services which are not required in order to save some code during the debug session. The optimiser can make a big difference to code size but the down side is the additional debugging difficulty involved. It is possible to debug but it involves a certain amount of practice to learn the tricks involved.

I still think that there should be no need to debug the stuff you are working on at the moment on the target - the simulator is the best choice once you get it working - I think that this should be possible as noted in the last post.

Regards

Mark

Offline thamanjd

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #8 on: October 04, 2007, 10:40:06 AM »
Regarding debugging in Codewarrior.
I agree that the debugger not stopping on certain breakpoints is very frustrating.
I guess this happens because the optimised assembly doesn't resemble the c code so much any more.
For instance if you were setting bits of a register one at a time thinking oud like to see the effects in hardware, the optimisation tends to turn what might have been eight lines of assembly into one line.
i.e.


PORTB |= 0x01;
PORTB |= 0x02;
PORTB |= 0x04;
PORTB |= 0x08;

would effectively get turned into

PORTB|=0x0F;

completely destroying the effect you were after.

while i'm debugging i'll surround the breakpoint or the code i want to step through with
 asm("nop");

so...

asm("nop");
PORTB |= 0x01;
asm("nop");
PORTB |= 0x02;
asm("nop");
PORTB |= 0x04;
asm("nop");
PORTB |= 0x08;
asm("nop");

then the compiler can't lump all the bit sets together and i can step through them.

I wish codewarrior had more compiling options for debugging some bits of code like this

John Dowdell

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #9 on: October 04, 2007, 11:27:59 AM »
Hi All

There is a very complete document about CW for the Coldfire (possibly also for HCS12 etc.) called "Code Warrior Build Tools Reference Coldfire(TM) Architectures Edition" available on the Freescale web site:
http://www.freescale.com/files/soft_dev_tools/doc/ref_manual/ColdFire_Build_Tools_Reference.pdf

There is a pragma which will possibly allow individual routines to be compiled with dirrerent settings to the global optimiser setting.

#pragma global_optimizer on | off | reset

I expect that if you play around with this it may enable debugging in unoptimised code in single routines.

In John Dowdell's case - have you tried changing the port define to be volatile? This should stop the compiler saving instructions in the case illustrated. In fact I don't like the fact that PORTA, PORTB etc. are not defined as volatile since they can change between read cycles. I will make this change also in the master copy of the NE64 project code!

Regards

Mark


Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #10 on: October 04, 2007, 02:55:33 PM »
Mark and John,
 I disabled all unnessescary services and turned off global
optimazation and set either the "faster execution" or "smaller code size" options and still couldn't get CW to break on the C function fnInsertString() in webinterface.c !
 I also tried setting the #pragma global_optimizer off at the beginning
of the webinterface file with no luck.

 Thanks,
 John

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #11 on: October 04, 2007, 03:24:48 PM »
Mark, I did get the project to run in VC and was able to set a break point in webinterface.c
I FTP'ed the web pages up to the simulated machine and was able to view them via the
browser. That was neat :)
I will modify the web pages to pad out the £xyz tags to 5 chars and will modify webinterface.c and webutils.c as you suggested and see if it works. I'll keep you posted.

 Thanks for the help ...
 John
 

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #12 on: October 04, 2007, 04:36:56 PM »
Hi John

I hope this works well for you.

I never work on the target for such development. The simulator does it all and allows such more comfortable debugging. You can also monitor all traffic with Ethereal and, if you have a tricky case, play the recording back again and again until you get it right. Working in this 'offline' mode also means that your TCP connection doesn't disconnect due to the breakpoint, which is a big nuisance otherwise when working on a real target!

All of your web pages are store in 'simulated' FLASH and its content is saved to your hard disk each time you close the simulator (not when terminating the debugger though so simply abort the program if you want to test again without modified FLASH contents) so that it really doesn't differ from a real target during the work.

I am sure that this will save you a lot of project time and you can work independently of any hardware.

Good luck

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #13 on: October 04, 2007, 07:31:17 PM »
Mark, I padded out all the £xyz tags to 5 chars in the HTML files by adding a space at the end. I modified fnWebParGenerator() in webutils.c as follows, using the WEB_ESCAPE_LEN
define, which is now 5:

 while (usLen) {       // We scan the HTTP frame to be sent, looking for a position to fill out
        if (*ptrBuffer++ == (unsigned char)WEB_PARSER_START) {       // a field has
            // if (usLen <= 4) {                                            // check whether long enough s
            if (usLen <= WEB_ESCAPE_LEN) {                               // check whether long


 // ptrBuffer += 2;                                              // jump over parameters
 // usLen -= 3;
 ptrBuffer += (WEB_ESCAPE_LEN-2);                     // jump over parameters
usLen -= (WEB_ESCAPE_LEN-1);


 and modified  fnInsertHTMLString() in webutils.c to replace all occurances of 4
with WEB_ESCAPE_LEN.

 So far it looks like it didn't break any existing code. I'll code my web pages to use the extended length and test it with the simulator.


 Thanks for the help,
 John

 

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Debuging webinterface.c in Cw 6.3 Lite
« Reply #14 on: October 04, 2007, 08:41:20 PM »
Hi John

This sounds very promising. I will do the same in the project code since it may well be useful for other work.

Good luck with the coding and testing.

Regards

Mark