Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By GregShu
#57395 First, I'm not sure in which forum this post is best suited as it has to do with compiling, but I am using the Arduino IDE.

My problem is I can't get even the simplest program to compile with the GDBStub. Digging deeper I can't see how it is supposed to work. All of the instructions I have found say that one of the initial steps is to #include <GDBStub.h>, but this header does nothing. It's contents are as follows:
Code: Select all#ifndef GDBSTUB_H
#define GDBSTUB_H

// this header is intentionally left blank

#endif //GDBSTUB_H

Attempts to compile this test program...
Code: Select all#include <GDBStub.h>

void setup() {
  gdbstub_init();
}

void loop() {
}

... result in this error: 'gdbstub_init' was not declared in this scope. Makes sense because nothing is defined in <GDBStub.h>.

In a child directory (internal) within the library is a header file named "gdbstub.h" in which gdbstub_init() is defined.
Code: Select all#ifndef GDBSTUB_H
#define GDBSTUB_H

#ifdef __cplusplus
extern "C" {
#endif

void gdbstub_init();

#ifdef __cplusplus
}
#endif

#endif

When I copy the library's files to a directory named lib in my project directory and change <GDBStub.h> to "lib/gdbstub.h" I receive a different error when I try to compile: undefined reference to `gdbstub_init'.

Please set me straight.
User avatar
By GregShu
#57527 Thank you for your insight. Valuable information I found nowhere else.

I can now successfully compile my simple test program, and have moved up to a slightly more capable test program (see below).
Code: Select all#include <GDBStub.h>

int ledState = LOW;     

unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}

void loop()
{
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;  // Note that this switches the LED *off*
    else
      ledState = LOW;   // Note that this switches the LED *on*
    digitalWrite(LED_BUILTIN, ledState);
  }
}

If I set GDBSTUB_BREAK_ON_INIT to 1 in gdbstub-cfg.h the blinking does not start as expected, and when set to 0 it blinks. Based on this I assume that the code on the ESP is working properly.

Launching xtensa-lx106-elf-gdb I enter the following commands at the (gdb) prompt:
Code: Select allfile /Volumes/RAMDisk/gdbstub_test.ino.elf
set remote hardware-breakpoint-limit 1
set remote hardware-watchpoint-limit 1
set debug xtensa 4
set remotebaud 115200
target remote /dev/tty.SLAB_USBtoUART

Everything appears to be working until the last command. The (gdb) prompt does not return. Pressing control-C returns ^C/dev/tty.SLAB_USBtoUART: Interrupted system call.. Entering c at this point returns The program is not being run..

It appears that break, list, print commands are all working. I just can communicate with the ESP.