GDB Set Breakpoint Question

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • GDB Set Breakpoint Question

    I'm using the J-Link USB device and the Code Sourcery Command Line GDB Debugger.

    When using the GDB command "setbp", this command wants the address to where you want to break.
    Example: monitor setbp 0x00, where 0x00 is the address you want to break at.
    My question is where do you get the memory addresses from? Are they from the .lst or .map or .elf files?



    Thanks.


    The post was edited 1 time, last by freddie ().

  • Hello freddie,

    an easy way to locate the address of the instruction you want to breakpoint is, to use the combination of list + map file.
    Use the map file in order to locate the address of a function entry and the list file in order to locate the offset of the instruction inside the function.

    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thanks Alex,

    Can you help me with one example...
    In the .map and .lst files below, I want to set a break point at the following line in the .lst file:
    179:main_FullCAN.c **** LEDvalue <<= 1; .
    What would the breakpoint addess be? Also, is there any documentation on how to read the .map and ,lst file?

    Thanks.

    Source Code

    1. .map file....
    2. *(.text .text.*)
    3. .text 0x00000000 0x160 Startup.o
    4. 0x00000000 _startup
    5. .text 0x00000160 0x1fc main_FullCAN.o
    6. 0x00000160 DefaultISR
    7. 0x00000164 Timer0ISR
    8. 0x00000200 main
    9. 0x0000019c IsTimeExpired
    10. 0x000001d4 SlowDown
    11. .text 0x0000035c 0x5d0 LPC_FullCAN_SW.o
    12. 0x000007e0 FullCAN_CANISR_Err
    13. 0x00000488 FullCAN_SetFilter
    14. 0x0000035c FullCAN_Init
    15. 0x00000888 FullCAN_CANISR_Rx2
    16. 0x00000654 FullCAN_SetErrIRQ
    17. 0x000007e4 FullCAN_CANISR_Rx1
    18. 0x0000068c FullCAN_PushMessage
    19. 0x0000072c FullCAN_PullMessage
    Display All




    Source Code

    1. .lst File
    2. 147 .global main
    3. 149 main:
    4. 150 .LFB6:
    5. 108:main_FullCAN.c ****
    6. 109:main_FullCAN.c ****
    7. 110:main_FullCAN.c **** /**************************************************************************
    8. 111:main_FullCAN.c **** DOES: Main routine of demo program:
    9. 112:main_FullCAN.c **** 1.) Initialization
    10. 113:main_FullCAN.c **** 2.) Send a single CAN message
    11. 114:main_FullCAN.c **** 3.) Wait for CAN message,
    12. 115:main_FullCAN.c **** send response to received messages
    13. 116:main_FullCAN.c **** GLOBALS: none
    14. 117:main_FullCAN.c **** RETURNS: never
    15. 118:main_FullCAN.c **** ***************************************************************************/
    16. 119:main_FullCAN.c **** int main(void)
    17. 120:main_FullCAN.c **** {
    18. 151 .loc 1 120 0
    19. 152 @ Function supports interworking.
    20. 153 @ args = 0, pretend = 0, frame = 16
    21. 154 @ frame_needed = 0, uses_anonymous_args = 0
    22. 155 00a0 7F402DE9 stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, lr}
    23. 156 .LCFI2:
    24. 121:main_FullCAN.c **** FULLCAN_MSG MsgBuf; // Buffers one CAN message
    25. 122:main_FullCAN.c **** unsigned int LEDvalue = 0x10000000L; // Used for LED output
    26. 123:main_FullCAN.c ****
    27. 124:main_FullCAN.c **** // No divider: peripheral clock = processor clock
    28. 125:main_FullCAN.c **** VPBDIV = 1;
    29. 157 .loc 1 125 0
    30. 158 00a4 18319FE5 ldr r3, .L24
    31. 159 00a8 0160A0E3 mov r6, #1
    32. 160 00ac 0060C3E5 strb r6, [r3, #0]
    33. 126:main_FullCAN.c ****
    34. 127:main_FullCAN.c **** // Init Vector Interrupt Controller
    35. 128:main_FullCAN.c **** VICIntEnClr = 0xFFFFFFFFL; // Disable all Ints
    36. 129:main_FullCAN.c **** VICIntSelect = 0x00000000L;
    37. 130:main_FullCAN.c ****
    38. 131:main_FullCAN.c **** // Install Default IRQVec
    39. 132:main_FullCAN.c **** VICDefVectAddr = (unsigned long) DefaultISR; // set interrupt vector
    40. 161 .loc 1 132 0
    41. 162 00b0 10319FE5 ldr r3, .L24+4
    42. 163 .loc 1 128 0
    43. 164 00b4 0040E0E3 mvn r4, #0
    44. 165 .loc 1 129 0
    45. 166 00b8 0050A0E3 mov r5, #0
    46. 167 .loc 1 128 0
    47. 168 00bc EB4F04E5 str r4, [r4, #-4075]
    48. 133:main_FullCAN.c ****
    49. 134:main_FullCAN.c **** // Initialisation of CAN interfaces
    50. 135:main_FullCAN.c **** // CAN interface 1, use IRQVec0, at 125kbit
    51. 136:main_FullCAN.c **** FullCAN_Init(1,0,CANBitrate125k_12MHz);
    52. 169 .loc 1 136 0
    53. 170 00c0 0510A0E1 mov r1, r5
    54. 171 .loc 1 129 0
    55. 172 00c4 F35F04E5 str r5, [r4, #-4083]
    56. 173 .loc 1 136 0
    57. 174 00c8 FC209FE5 ldr r2, .L24+8
    58. 175 .loc 1 132 0
    59. 176 00cc CB3F04E5 str r3, [r4, #-4043]
    60. 177 .loc 1 136 0
    61. 178 00d0 0600A0E1 mov r0, r6
    62. 179 00d4 FEFFFFEB bl FullCAN_Init
    63. 137:main_FullCAN.c **** // CAN interface 2, use IRQVec1, at 125kbit
    64. 138:main_FullCAN.c **** FullCAN_Init(2,1,CANBitrate125k_12MHz);
    65. 180 .loc 1 138 0
    66. 181 00d8 0610A0E1 mov r1, r6
    67. 182 00dc E8209FE5 ldr r2, .L24+8
    68. 183 00e0 0200A0E3 mov r0, #2
    69. 184 00e4 FEFFFFEB bl FullCAN_Init
    70. 139:main_FullCAN.c ****
    71. 140:main_FullCAN.c **** // Init LED ports
    72. 141:main_FullCAN.c **** IODIR1 = 0x00FF0000; // P1.16..23 defined as Outputs
    73. 185 .loc 1 141 0
    74. 186 00e8 E0209FE5 ldr r2, .L24+12
    75. 187 00ec FF38A0E3 mov r3, #16711680
    76. 188 00f0 183082E5 str r3, [r2, #24]
    77. 142:main_FullCAN.c ****
    78. 143:main_FullCAN.c **** // Init Input ports
    79. 144:main_FullCAN.c **** IODIR0 = 0x00000000; // define pins 0-7 as inputs
    80. 145:main_FullCAN.c ****
    81. 146:main_FullCAN.c **** // Set CAN Err ISR to IRQVec2
    82. 147:main_FullCAN.c **** FullCAN_SetErrIRQ(2);
    83. 189 .loc 1 147 0
    84. 190 00f4 0200A0E3 mov r0, #2
    85. 191 .loc 1 144 0
    86. 192 00f8 085082E5 str r5, [r2, #8]
    87. 193 .loc 1 147 0
    88. 194 00fc FEFFFFEB bl FullCAN_SetErrIRQ
    89. 148:main_FullCAN.c ****
    90. 149:main_FullCAN.c **** // Initialize Timer Interrupt
    91. 150:main_FullCAN.c **** T0MR0 = 5999; // 100 microseconds = 6.000-1 counts
    92. 195 .loc 1 150 0
    93. 196 0100 CC209FE5 ldr r2, .L24+16
    94. 197 0104 CC309FE5 ldr r3, .L24+20
    95. 198 0108 183082E5 str r3, [r2, #24]
    96. 151:main_FullCAN.c **** T0MCR = 3; // Interrupt and Reset on MR0
    97. 199 .loc 1 151 0
    98. 200 010c 0330A0E3 mov r3, #3
    99. 201 0110 143082E5 str r3, [r2, #20]
    100. 152:main_FullCAN.c **** T0TCR = 1; // Timer0 Enable
    101. 153:main_FullCAN.c ****
    102. 154:main_FullCAN.c **** // Set Timer0 ISR to IRQVec3
    103. 155:main_FullCAN.c **** VICVectAddr3 = (unsigned long) Timer0ISR; // set interrupt vector
    104. 202 .loc 1 155 0
    105. 203 0114 C0309FE5 ldr r3, .L24+24
    106. 204 .loc 1 152 0
    107. 205 0118 046082E5 str r6, [r2, #4]
    108. 206 .loc 1 155 0
    109. 207 011c F33E04E5 str r3, [r4, #-3827]
    110. 156:main_FullCAN.c **** VICVectCntl3 = 0x20 | 4; // use it for Timer 0 Interrupt
    111. 208 .loc 1 156 0
    112. 209 0120 2430A0E3 mov r3, #36
    113. 210 0124 F33D04E5 str r3, [r4, #-3571]
    114. 157:main_FullCAN.c **** VICIntEnable = 0x00000010; // enable Timer0 Interrupt
    115. 211 .loc 1 157 0
    116. 212 0128 1030A0E3 mov r3, #16
    117. 213 012c EF3F04E5 str r3, [r4, #-4079]
    118. 158:main_FullCAN.c ****
    119. 159:main_FullCAN.c **** // Receive message with ID 101h on CAN 2
    120. 160:main_FullCAN.c **** FullCAN_SetFilter(2,0x101);
    121. 214 .loc 1 160 0
    122. 215 0130 A8109FE5 ldr r1, .L24+28
    123. 216 0134 0200A0E3 mov r0, #2
    124. 217 0138 FEFFFFEB bl FullCAN_SetFilter
    125. 161:main_FullCAN.c ****
    126. 162:main_FullCAN.c **** // Receive message with ID 201h on CAN 2
    127. 163:main_FullCAN.c **** FullCAN_SetFilter(2,0x201);
    128. 218 .loc 1 163 0
    129. 219 013c A0109FE5 ldr r1, .L24+32
    130. 220 0140 0200A0E3 mov r0, #2
    131. 221 0144 FEFFFFEB bl FullCAN_SetFilter
    132. 164:main_FullCAN.c ****
    133. 165:main_FullCAN.c **** // Receive message with ID 102h on CAN 1
    134. 166:main_FullCAN.c **** FullCAN_SetFilter(1,0x102);
    135. 222 .loc 1 166 0
    136. 223 0148 98109FE5 ldr r1, .L24+36
    137. 224 014c 0600A0E1 mov r0, r6
    138. 225 0150 FEFFFFEB bl FullCAN_SetFilter
    139. 167:main_FullCAN.c ****
    140. 168:main_FullCAN.c **** // Receive message with ID 202h on CAN 1
    141. 169:main_FullCAN.c **** FullCAN_SetFilter(1,0x202);
    142. 226 .loc 1 169 0
    143. 227 0154 90109FE5 ldr r1, .L24+40
    144. 228 0158 0600A0E1 mov r0, r6
    145. 229 015c FEFFFFEB bl FullCAN_SetFilter
    146. 170:main_FullCAN.c ****
    147. 171:main_FullCAN.c **** // DEBUG HELP:
    148. 172:main_FullCAN.c **** // Wait for 10 milliseconds, to allow debug hardware to catch up
    149. 173:main_FullCAN.c **** SlowDown(100);
    150. 230 .loc 1 173 0
    151. 231 0160 6400A0E3 mov r0, #100
    152. 232 0164 FEFFFFEB bl SlowDown
    153. 233 0168 114284E2 add r4, r4, #268435457
    154. 234 .LVL9:
    155. 235 .L22:
    156. 174:main_FullCAN.c ****
    157. 175:main_FullCAN.c **** while (1)
    158. 176:main_FullCAN.c **** {// Loop forever
    159. 177:main_FullCAN.c ****
    160. 178:main_FullCAN.c **** // Handle LEDs
    161. 179:main_FullCAN.c **** LEDvalue <<= 1;
    162. 236 .loc 1 179 0
    163. 237 016c 8440A0E1 mov r4, r4, asl #1
    164. 180:main_FullCAN.c **** if (LEDvalue > 0x00800000L)
    165. 181:main_FullCAN.c **** {
    166. 182:main_FullCAN.c **** LEDvalue = 0x00010000L;
    167. 183:main_FullCAN.c **** }
    168. 184:main_FullCAN.c **** IOSET1 = LEDvalue;
    169. 238 .loc 1 184 0
    170. 239 0170 58309FE5 ldr r3, .L24+12
    171. 240 .loc 1 180 0
    172. 241 0174 020554E3 cmp r4, #8388608
    173. 242 0178 0148A083 movhi r4, #65536
    174. 243 .loc 1 184 0
    175. 244 017c 144083E5 str r4, [r3, #20]
    176. 185:main_FullCAN.c **** if (IOPIN0 & 1<<2)
    177. 245 .loc 1 185 0
    178. 246 0180 003093E5 ldr r3, [r3, #0]
    179. 247 0184 040013E3 tst r3, #4
    180. 248 0188 0800000A beq .L21
    181. 186:main_FullCAN.c **** {
    182. 187:main_FullCAN.c **** // CAN Message: 677 00 01 02 03 04 05 06 07
    183. 188:main_FullCAN.c **** MsgBuf.Dat1 = 0x00080677L; // 8 bytes, ID 0x302
    184. 249 .loc 1 188 0
    185. 250 018c 5C309FE5 ldr r3, .L24+44
    186. 251 0190 04308DE5 str r3, [sp, #4]
    187. 189:main_FullCAN.c **** MsgBuf.DatA = 0x03020100L; //
    188. 252 .loc 1 189 0
    189. 253 0194 58309FE5 ldr r3, .L24+48
    Display All
  • Hello freddie,

    please have a look into the documentation of your compiler & linker to get information
    about how to interpret the generated list and map files.

    In your case you should set the breakpoint at addr 0x0000036c

    main is placed at 0x00000200
    The line you want to breakpoint is placed at offset 0x016c in main:
    78:main_FullCAN.c **** // Handle LEDs
    179:main_FullCAN.c **** LEDvalue <<= 1;
    236 .loc 1 179 0
    237 016c 8440A0E1 mov r4, r4, asl #1


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - Alex wrote:

    Hello freddie,

    please have a look into the documentation of your compiler & linker to get information
    about how to interpret the generated list and map files.

    In your case you should set the breakpoint at addr 0x0000036c

    main is placed at 0x00000200
    The line you want to breakpoint is placed at offset 0x016c in main:
    78:main_FullCAN.c **** // Handle LEDs
    179:main_FullCAN.c **** LEDvalue <<= 1;
    236 .loc 1 179 0
    237 016c 8440A0E1 mov r4, r4, asl #1


    Best regards
    Alex

    Thanks Alex. This memory address did not work for me. I compared the memory address calculated using this method vs. the memoy address that Insight tells me and they are not the same. I tried it with a few other examples and Insight is always differs. When I set the breakpoint at the address Insight tells me the program breaks correctly. Using this method it does not break correctly. I wonder what could be going on? Thanks.