Author Topic: Help With Debugging an AVR Using GDB [SOLVED]  (Read 556 times)

0 Members and 1 Guest are viewing this topic.

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Help With Debugging an AVR Using GDB [SOLVED]
« on: June 05, 2021, 02:58:50 am »
I'm trying to debug a program running on an ATtiny84A, and I am having trouble understanding either how to use it, or interpreting its output, or both. For testing purposes, I created a simple program that I have uploaded to the microcontroller which simply sets the value of a test variable `unsigned char test_var=0xAA`, and outputs a LOW to PORTA6. I then put the microcontroller into debug mode, and started debugging with GDB.

First I wanted to print the value of the test variable, so I typed `print test_var`, which output `$9 = 170 '\252'`
I am guessing `$9` refers to the output count, and I know that 170 = 0xAA, but I don't know what `'\252'` means.

Next I changed the variable to a `char` instead of an `unsigned char` and ran the same `print test_var`, I got an output of `$10 = -86 '\252'` which doesn't make a lot of sense to me. As far as I was aware, when you have a signed char (or just char) the MSB of the byte indicates the sign of the number, so if there is a `1` at BIT7 of the byte, it means that its a negative number, so when you look at `0xAA` you have `0b10101010`. At BIT7 you have a `1` so that means that the number is negative, which makes sense; however, the preceding 7 bits `0b0101010`, when converted to decimal is equal to 42, so the number SHOULD be -42, but according to GDB it's -86. What Am I understanding wrong with that?


Next I wanted to read the direction register DDRA since I set DDA6 as an output for PORTA6 to be set LOW. From this I would know that the DDA6 bit of DDRA should be a 1 so I wanted to print the contents of DDRA to see that.
First I tried `print DDRA` which output `= 0 '\000'` which doesn't make sense because I know that there should be a bit set at DDA6, and yet this is saying that no bits are set in that register. On top of that, there is a '\000' which is different from the '\252' from before.

I thought that maybe It needed the physical memory address of the register so I looked at the end of the ATtiny84A datasheet in the Register Summary section and saw that DDRA had memory address 0x1A (0x3A) (I am not sure what the second value in brackets refers to so I tried both), so I then tried `print 0x1A` which output `= 26` and `print 0x3A` which output `= 58` neither of which make sense because I should see 64 indicating that BIT6 of DDRA has been set. And on top of this, these outputs are missing the '\000' and '\252' from before.

Where is my understanding going wrong? I'm getting such different values with everything and I have absolutely no idea why, and I would love some help.

Thank you!
« Last Edit: June 05, 2021, 04:07:32 am by Kalcifer »
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1250
  • Country: us
  • The other white meat.
Re: Help With Debugging an AVR Using GDB
« Reply #1 on: June 05, 2021, 03:05:49 am »
\252 is octal. This is a standard C escape code.

https://en.wikipedia.org/wiki/Escape_sequences_in_C

C typically uses two's compliment not one's compliment.

https://en.wikipedia.org/wiki/Two%27s_complement
 
The following users thanked this post: Kalcifer

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Re: Help With Debugging an AVR Using GDB
« Reply #2 on: June 05, 2021, 04:04:09 am »
Next I wanted to read the direction register DDRA since I set DDA6 as an output for PORTA6 to be set LOW. From this I would know that the DDA6 bit of DDRA should be a 1 so I wanted to print the contents of DDRA to see that.
First I tried `print DDRA` which output `= 0 '\000'` which doesn't make sense because I know that there should be a bit set at DDA6, and yet this is saying that no bits are set in that register. On top of that, there is a '\000' which is different from the '\252' from before.
I thought that maybe It needed the physical memory address of the register so I looked at the end of the ATtiny84A datasheet in the Register Summary section and saw that DDRA had memory address 0x1A (0x3A) (I am not sure what the second value in brackets refers to so I tried both), so I then tried `print 0x1A` which output `= 26` and `print 0x3A` which output `= 58` neither of which make sense because I should see 64 indicating that BIT6 of DDRA has been set. And on top of this, these outputs are missing the '\000' and '\252' from before.

as found elsewhere, the reason I wasn't able to read DDRA was because I had never started the program. After running `continue`  the register value updated and output 64 as expected when using the `print DDRA` command; however `print 0x1A` , and `print 0x3A` both still output 26 and 58, and I am unsure as to why.
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Re: Help With Debugging an AVR Using GDB
« Reply #3 on: June 05, 2021, 04:07:12 am »
 

Offline bson

  • Supporter
  • ****
  • Posts: 1963
  • Country: us
Re: Help With Debugging an AVR Using GDB [SOLVED]
« Reply #4 on: June 07, 2021, 08:55:11 pm »
print/x will print a value in hex.  Or just p/x
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 3186
  • Country: ro
Re: Help With Debugging an AVR Using GDB [SOLVED]
« Reply #5 on: June 07, 2021, 09:19:24 pm »
You might find GDB more intuitive and productive when used with a GUI/IDE:



Only a generic USB to TTL serial adapter and a diode needed (as a one-wire debugger/programmer), the rest is FOSS:
https://www.eevblog.com/forum/microcontrollers/avr-(arduino)-linux-debug/

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 624
  • Country: gb
Re: Help With Debugging an AVR Using GDB
« Reply #6 on: June 11, 2021, 05:44:39 am »
however `print 0x1A` , and `print 0x3A` both still output 26 and 58, and I am unsure as to why.

0x10 hex = 16 decimal

0xA = 10

Hopefully you can see where this is going...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf