Allen yang Posted April 8 Report Share Posted April 8 Nowadays, I use at function to access vector and it out of range. However, it didn't pause and the program shutdown only. #include <systemc> int sc_main(int args, char* argv[]) { std::vector<int> vec = {1, 2, 3}; int num1 = vec.at(1); int num2 = vec.at(10); return 0; } Here's the result: root@xxx:/home# SystemC 2.3.3-Accellera --- Jan 25 2024 15:41:45 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED Error: (E549) uncaught exception: vector::_M_range_check: __n (which is 10) >= this->size() (which is 3) In file: ../../../src/sysc/kernel/sc_except.cpp:101 root@xxx:/home# I expected it will be like below, and the program will be crash and output coredump file. terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 10) >= this->size() (which is 3) Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted April 8 Report Share Posted April 8 Hello @Allen yang, It is because sc_main is called within a context of a try catch block. See this: https://github.com/accellera-official/systemc/blob/bec101067d808f93bf215031dff6fa9ab7035995/src/sysc/kernel/sc_main_main.cpp#L66-L108\ Captured the snippet from the implementation and reproduced below. try { pln(); // Perform initialization here sc_in_action = true; // copy array of pointers to keep allocated pointers for later release std::vector<char*> argv_call = argv_copy; status = sc_main( argc, &argv_call[0] ); // Perform cleanup here sc_in_action = false; } catch( const sc_report& x ) { sc_report_handler::get_handler() ( x, sc_report_handler::get_catch_actions() ); } catch( ... ) { // translate other escaping exceptions sc_report* err_p = sc_handle_exception(); if( err_p ) sc_report_handler::get_handler() ( *err_p, sc_report_handler::get_catch_actions() ); delete err_p; } You can see there is a broader catch( ... ) statement which is causing the exception to be handled instead of being thrown. You can possibly try writing you own main function but will need to take care of additional SystemC kernel initialization sequences. Hope this helps. Regards, Ameya Vikram Singh Allen yang 1 Quote Link to comment Share on other sites More sharing options...
Allen yang Posted April 8 Author Report Share Posted April 8 Hi @AmeyaVS, Thank you for your help. Do you mean that I should rewrite `sc_main_main.cpp` by myself fixing `catch(...) ...` code ? Can I just use code below? catch( ... ) { // don't translate other escaping exceptions } Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted April 8 Report Share Posted April 8 Hello @Allen yang, You could try removing the catch all block itself, so that the exceptions is thrown from the sc_main method. Regards, Ameya Vikram Singh Allen yang 1 Quote Link to comment Share on other sites More sharing options...
Allen yang Posted April 8 Author Report Share Posted April 8 I have try your advice and it works. Thanks! Quote Link to comment Share on other sites More sharing options...
Allen yang Posted April 9 Author Report Share Posted April 9 Hi @AmeyaVS, When I try `vector::at` in `SC_METHOD` or `SC_(C)THREAD`, the stack can't be show. I try to rewrite `sc_except.cpp::sc_handle_exception`, it didn't work. Can you help me figure out this? Regards, Allen Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted April 9 Report Share Posted April 9 2 hours ago, Allen yang said: I try to rewrite `sc_except.cpp::sc_handle_exception`, it didn't work. Can you help me figure out this? Hello @Allen yang, It is possible to get a stack trace, but then again what is your use-case? Regards, Ameya Vikram Singh Quote Link to comment Share on other sites More sharing options...
Allen yang Posted April 10 Author Report Share Posted April 10 12 hours ago, AmeyaVS said: Hello @Allen yang, It is possible to get a stack trace, but then again what is your use-case? Regards, Ameya Vikram Singh My use-case is in `SC_METHOD` or `SC_(C)THREAD` if exception caught I can see the ori stack trace with c++ not rethrow or caught by `sc_report`. The stack trace isn't my exception. I don't want to use `catch throw` to get stack trace which I really need. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.