Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
reduce stack size in debug session to catch endless recursion

I have a algorithm which "sometimes" did not break the recursion and ends up in a stack overflow. Now I want to debug that situation. gdb points me directly to the line where I overwrite the stack boarder, but it is impossible to get a stacktrace because gdb needs endless time to unwind the stack and display it in ddd.

I now simply want to reduce the stack size to get the corruption much earlier. So I need a way to reduce to stack for my running task. There are no threads involved so it should be not such a big deal.

But I have no idea if gdb itself has an option to manipulte the stack (size) itself or I need to programmatic change the size at start of my prog or I can maybe reduce the size from the os command line ( linux ) after starting the debug session.

Maybe it is also possible the stop if the call tree reaches a maximum depth if gdb has such an option.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try to use ulimit -s (stack_size) in shell where you run your program or you can do it programmatically Change stack size for a C++ application in Linux during compilation with GNU compiler

EDIT:

We can write simple nohup-like program, which send SIGSTOP to itself, and than execute it's arguments. Let's name it runpaused

//runpaused.c
#include <signal.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    raise(SIGSTOP);
    return execvp(argv[1], argv+1);
}

Than, we can do next things: compile runpaused

$ gcc runpaused.c -o runpaused

limit stack for current shell

$ ulimit -s 32

run our program via runpaused, use sh as example

$ ./runpaused sh -c "echo Hello"

From other terminal: find it's PID

$ ps -ef | grep -v grep | grep runpaused

load gdb with our program

$ gdb $(which sh)

attach to PID

(gdb) attach PID

send signal SIGCONT from gdb

(gdb) signal SIGCONT

continue program execution from gdb

(gdb) continue

After several times of continuing, we get what we want.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda