1

I am trying to use ARMCC Keil toolchain with CMake in vscode. I copied asm/compiler/linker flag from a working Keil project, except that I don't use .crf and .d files everywhere.

I have a strange behavior while being in debug with Cortex-debug extension in vscode. It compiles, links, but I noticed that when a function pointer is initialized at NULL, its value is evaluated at 0xffffffff.

To witness this more precisely (the application I am trying to build is quite big), I added code at the very beginning of main:

typedef void (*function_pointer)(void); 
static function_pointer function = NULL; 
/* ------------------------------------------------------------------- */ 
/**. * @brief Function for application main entry. */ 
int main(void) { 
 if(function != NULL) 
 { 
 function = (function_pointer)NULL;
 function();
 } 
. 
. 
. 

Debugger breaks within the if statement (so function is indeed not NULL while it should) After the NULL assignement, function is not assigned.

When I add a preprocess flag, I can be sure that NULL is expanded to 0 :

typedef void (*function_pointer)(void); 
static function_pointer function = 0; 
int main(void) {
 if(function != 0)
 {
 function = (function_pointer)0;
 function();
 } 

Note that I generate a .elf file with CMake but Keil generate a .axf file (which should be the same, as ELF files are standard).

I tried to generate.crf files and .d files but I am not sure they're needed with Cortex-debug vscode extension.

Also, I noticed that the programming behavior changes wether I program via Keil or via vscode. It takes much less time in vscode and the led on my debug board that blink sometimes with Keil doesn't light with vscode.

I can provide all details (CMake generation/compiler/linker commands, scatter file, debug launch command etc...). It is just that I wanted the question to be clear, and not provide 100+ lines of code, but feel free to ask anything

Thank you for your help

asked Mar 26, 2024 at 17:57
6
  • See Is NULL always zero in C? TLDR: No, NULL does not have to be zero. Commented Mar 26, 2024 at 23:44
  • 1
    Still, comparing a pointer to NULL should still indicate whether it's a null-pointer or not. I'm more concerned about this "Keil" thing. Looks like an embedded platform to me... which means I wouldn't rule out the idea that globals might not be initialized at all. Might actually try to start main() with an unconditional assignment of NULL to the pointer. Or test the theory by making another global, like "static int test=55" and see if that works out... Commented Mar 27, 2024 at 0:03
  • Indeed, I wanted to be sure it was not 0xffffffff @ChristianStieber yes, it is an embedded system oriented platform (specific to ARM targets). I tried your idea and test is initialized at 0x157fffff... I don't understand, on Keil it works great. Also I just noticed that the programming behavior changes between platforms. It takes much less time in vs code and on my debug board, the led that blink sometimes while flashing with keil doesn't light when flashing with vscode. I will edit the post to add this info Commented Mar 27, 2024 at 8:58
  • This is a bit unclear, but you are using the exactly same compiler on both, right? And you have verified that compilation commands generated by both build systems are 100% identical? Commented Mar 27, 2024 at 9:45
  • @user694733 yes, I am using same compiler/linker but not the same objdump and nm program (Keil debug vs Cortex-debug in vscode). No, it is not the exact same compiler commands, as I don't generate .crf files and .d files. And even though the sources are the same, the entire hierarchy of the project has changed so all include path are different, and so does .o files output directories. All other flags are the same. I don't have the possibility to have the complete command on Keil unfortunately. Commented Mar 27, 2024 at 10:19

1 Answer 1

0

I had a warning in GDB output : Loadable section "IRAM1" outside elf section. I tweaked the scatter file and manipulated the elf in order to please GDB and its ok. GDB wasn't finding ZI data, so I assume it was doing nonsense when trying to evaluate them.

answered Apr 23, 2024 at 7:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.