/** * @brief Program entry point. * @param none * @retval 0 */ int main(void) { RCC_ClocksTypeDef RCC_Clocks; SystemInit(); // Get the clock rate so we can set the sampling rate correctly. RCC_GetClocksFreq(&RCC_Clocks); ClockRate = RCC_Clocks.HCLK_Frequency; // NOTE: STM generic // Our timer (TIM2) uses the APB1 (PCLK1) clock. TimerBaseClockRate = RCC_Clocks.PCLK1_Frequency; // Set the SysTick interrupt to fire once every millisecond. SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 1000); LedInit(); // Turn the Orange LED on, signifying WAIT... LedSet(LED_ORANGE, LED_MODE_ON); UsartInit(); Copyright(); uint32_t commandTicks = Ticks; LedSet(LED_ORANGE, LED_MODE_OFF); // Loop forever... while (1) { if (SamplingActive) { LedSet(LED_RED, LED_MODE_OFF); // Turn the Blue LED on when sampling. LedSet(LED_BLUE, LED_MODE_ON); SampleLoop(); LedSet(LED_BLUE, LED_MODE_OFF); } // Check for commands every 1/10 second. if ((Ticks - commandTicks) >= 100) { ProcessCommands(); commandTicks = Ticks; } } return 0; }
void StartProg( char *cmd, char *prog, char *full_args, char *dos_args ) { char exe_name[PATH_MAX]; pid_t save_pgrp; pid_t pid; int status; MaxThread = 0; GrowArrays( 1 ); HaveRdebug = false; DbgDyn = NULL; OrigPGrp = getpgrp(); Attached = true; pid = Pid = SamplePid; /* allow attaching to existing process by pid */ if( pid == 0 || ptrace( PTRACE_ATTACH, pid, NULL, NULL ) == -1 ) { int num_args; size_t len; const char **argv; Attached = false; /* massage 'full_args' into argv format */ len = strlen( full_args ); num_args = SplitParms( full_args, NULL, len ); argv = alloca( ( num_args + 2 ) * sizeof( *argv ) ); argv[SplitParms( full_args, argv + 1, len ) + 1] = NULL; argv[0] = prog; Output( MsgArray[MSG_SAMPLE_1 - ERR_FIRST_MESSAGE] ); Output( prog ); Output( "\n" ); save_pgrp = getpgrp(); setpgid( 0, OrigPGrp ); pid = fork(); if( pid == -1 ) InternalError( MsgArray[MSG_SAMPLE_3 - ERR_FIRST_MESSAGE] ); if( pid == 0 ) { int rc; if( ptrace( PTRACE_TRACEME, 0, NULL, NULL ) < 0 ) { InternalError( MsgArray[MSG_SAMPLE_4 - ERR_FIRST_MESSAGE] ); } dbg_printf( "executing '%s'\n", prog ); for( rc = 0; argv[rc] != NULL; ++rc ) dbg_printf( "argv[%d] = '%s'\n", rc, argv[rc] ); rc = execve( prog, (char const * const *)argv, (char const * const *)environ ); dbg_printf( "execve() failed, returned %d\n", rc ); InternalError( MsgArray[MSG_SAMPLE_3 - ERR_FIRST_MESSAGE] ); // failsafe } setpgid( 0, save_pgrp ); strcpy( exe_name, prog ); } else if( pid ) { GetExeNameFromPid( pid, exe_name, PATH_MAX ); Output( MsgArray[MSG_SAMPLE_1 - ERR_FIRST_MESSAGE] ); Output( exe_name ); Output( "\n" ); } if( (pid != -1) && (pid != 0) ) { /* wait until it hits _start (upon execve) or gives us a SIGSTOP (if attached) */ if( waitpid( pid, &status, 0 ) < 0 ) goto fail; if( !WIFSTOPPED( status ) ) goto fail; if( Attached ) { if( WSTOPSIG( status ) != SIGSTOP ) { goto fail; } } else { if( WSTOPSIG( status ) != SIGTRAP ) { goto fail; } } DbgDyn = GetDebuggeeDynSection( exe_name ); errno = 0; } if( errno != 0 ) { pid = 0; } else { /* record information about main executable and initialize shared * library tracking */ InitLibMap(); CodeLoad( exe_name, 0, SAMP_MAIN_LOAD ); SampleLoop( pid ); FiniLibMap(); } return; fail: if( pid != 0 && pid != -1 ) { if( Attached ) { ptrace( PTRACE_DETACH, pid, NULL, NULL ); Attached = false; } else { ptrace( PTRACE_KILL, pid, NULL, NULL ); waitpid( pid, &status, 0 ); } } InternalError( MsgArray[MSG_SAMPLE_5 - ERR_FIRST_MESSAGE] ); }