Changeset dee1f89 for src/main.cc


Ignore:
Timestamp:
Aug 13, 2019, 2:35:54 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
1118b8b
Parents:
b3976bf
Message:

Libcfa make can now stop cfa-cpp when starting so a gdb session will be attached to it.
Use make ... gdbwaittarget=FILENAME where the filename is the same as the one printed when building with the silent rules.
cfa-cpp will print the gdb command to attach to it.
You may need to change linux permissions for gdb attach, just Google it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rb3976bf rdee1f89  
    1717#include <execinfo.h>                       // for backtrace, backtrace_symbols
    1818#include <getopt.h>                         // for no_argument, optind, geto...
    19 #include <signal.h>                         // for signal, SIGABRT, SIGSEGV
    2019#include <cassert>                          // for assertf
    2120#include <cstdio>                           // for fopen, FILE, fclose, stdin
    2221#include <cstdlib>                          // for exit, free, abort, EXIT_F...
     22#include <csignal>                         // for signal, SIGABRT, SIGSEGV
    2323#include <cstring>                          // for index
    2424#include <fstream>                          // for ofstream
     
    9696DeclarationNode * parseTree = nullptr;                                  // program parse tree
    9797
     98static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start
     99
    98100static std::string PreludeDirector = "";
    99101
     
    167169} // sigAbortHandler
    168170
    169 
    170171int main( int argc, char * argv[] ) {
    171172        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
     
    185186        parse_cmdline( argc, argv, filename );                          // process command-line arguments
    186187        CodeGen::FixMain::setReplaceMain( !nomainp );
     188
     189        if(waiting_for_gdb) {
     190                std::cerr << "Waiting for gdb" << std::endl;
     191                std::cerr << "run :" << std::endl;
     192                std::cerr << "  gdb attach " << getpid() << std::endl;
     193                raise(SIGSTOP);
     194        }
    187195
    188196        try {
     
    198206                } else {                                                                                // no input file name
    199207                        input = stdin;
     208                        std::cerr << "Input from stdin" << std::endl;
    200209                        // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass
    201210                        // a fake name along
     
    438447
    439448
    440 static const char optstring[] = ":hlLmNnpP:S:twW:D:F:";
     449static const char optstring[] = ":hlLmNnpP:S:tgwW:D:F:";
    441450
    442451enum { PreludeDir = 128 };
     
    453462        { "statistics", required_argument, nullptr, 'S' },
    454463        { "tree", no_argument, nullptr, 't' },
     464        { "gdb", no_argument, nullptr, 'g' },
    455465        { "", no_argument, nullptr, 0 },                                        // -w
    456466        { "", no_argument, nullptr, 0 },                                        // -W
     
    471481        "<directory> prelude directory for debug/nodebug",      // no flag
    472482        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    473         "build in tree",                                                                        // -t
     483        "building cfa standard lib",                                                                    // -t
     484        "wait for gdb to attach",                                                                       // -g
    474485        "",                                                                                                     // -w
    475486        "",                                                                                                     // -W
     
    582593                        Stats::parse_params( optarg );
    583594                        break;
    584                   case 't':                                                                             // build in tree
     595                  case 't':                                                                             // building cfa stdlib
    585596                        treep = true;
     597                        break;
     598                  case 'g':                                                                             // wait for gdb
     599                        waiting_for_gdb = true;
    586600                        break;
    587601                  case 'w':                                                                             // suppress all warnings, hidden
Note: See TracChangeset for help on using the changeset viewer.