Feature #367
log: implement lDebugAssert
Beginn:
22.02.2023
Abgabedatum:
% erledigt:
0%
Geschätzter Aufwand:
CS Zielversion:
Beschreibung
Biwak classes should be able to indicate errors in debug mode
that may be handled in application layer later.
lDebugAssert( sta == 2, "Could not write (%d)", sta);
- remove lAssertSta(); it can be done in an single macro, see below.
- implement pretty-print, see below.
- Only use lLog and lLogImpl; others are macros
- Implement lLogImpl in biwak
- Used macros: LEPTO_LOG_PRETTY_PRINT, FLASH_SIZE, LEPTO_LOG_PRETTY_PARAMS, \_\_FILENAME\_\_, Ansi-Codes, LEPTO_LOG_DEBUG, LEPTO_LOG_DEBUG_ASSERT
- Use different function names for pretty-print to force an linker error when configurations of compile units do not match
- adjust documentation
- measure 'cost' of feature
So lepto should also set \_\_FILENAME\_\_
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
Put the pretty logic into biwak cmake file in order not to put biwak logic into lepto:
set ( MCU_FLASH_SIZE 32768 )
if( MCU_FLASH_SIZE GREATER_EQUAL 65536 )
add_definitions( -DLEPTO_LOG_PRETTY_PRINT)
endif( MCU_FLASH_SIZE GREATER_EQUAL 65536 )
Historie
Von Maximilian Seesslen vor fast 2 Jahren aktualisiert
#include <QCoreApplication>
#include <main.hpp>
#include <stdarg.h>
//LEPTO_LOG_DEBUG_ASSERTIONS
#define FLASH_SIZE 65536
#if FLASH_SIZE >= 32768
#define LEPTO_LOG_PRETTY_PRINT
#endif
#if defined LEPTO_LOG_USE_PRETTY_PRINT
#define PRETTY_PARAMS const char*file, int line,
#if ! defined __FILENAME__
#define __FILENAME__ __FILE__
#warning "__FILENAME__" is not defined. Implement it in CMake to save memory.
#endif
#else
#define PRETTY_PARAMS
#endif
void lDebugImpl( PRETTY_PARAMS const char *format, ... )
{
va_list list;
va_start(list, format);
#if defined LEPTO_LOG_USE_PRETTY_PRINT
printf("%s(%d): ", file, line);
#endif
vprintf( format, list);
printf( "\n" );
return;
}
#if defined LEPTO_LOG_USE_PRETTY_PRINT
//#define lDebugAssert(a, b ,...) if(! (a)){lDebugImpl(__FILENAME__, __LINE__, "E: Assertion '" #a "' not true. " b , ##__VA_ARGS__);}
#define lDebugAssert(a, ...) if(! (a)) { lDebugImpl(__FILENAME__, __LINE__, "E: Assertion '" #a "' not true. " __VA_ARGS__ ) ; }
#else
#define lDebugAssert(a, ...) if(! (a)){lDebugImpl("E: Assertion '" #a "' not true. " __VA_ARGS__ );}
#endif
#define lAssert( assertion, ... ) if ( ! (assertion) ) \
lFatal( "Assertion wrong" __VA_ARGS__ );
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
int sta=1;
lDebugAssert( sta == 2, "Could not write (%d)", sta);
lDebugAssert( sta == 2 );
return (0); //app.exec();
}
Von Maximilian Seesslen vor fast 2 Jahren aktualisiert
Alignment would be also ok in the "pretty-print" version;
#if defined LEPTO_LOG_PRETTY_PRINT
int len=printf("%s(%d)" , file, line);
for(int i1=0; i1<20-len; i1++)
{
printf(".");
}
printf(": " ANSI_ORANGE);
#endif
Von Maximilian Seesslen vor fast 2 Jahren aktualisiert
- Beschreibung aktualisiert (diff)
How to measure the 'cost';
- Build debug (CANRec), release; track sizes
- create feature-branch
- implement it
- Build debug (CANRec) without PP, release without PP, both with PP; track size *
- campo.sh trackSizes
Von Maximilian Seesslen vor fast 2 Jahren aktualisiert
- Status wurde von Neu zu Erledigt geändert