@@ -98,7 +98,8 @@ SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
9898
9999 function onLine ( line ) {
100100 lines . push ( line ) ;
101- debug ( `[LINE][${ self . session . lldb . pid } ]` , line ) ;
101+ if ( self . session )
102+ debug ( `[LINE][${ self . session . lldb . pid } ]` , line ) ;
102103
103104 if ( ! regexp . test ( line ) )
104105 return ;
@@ -205,10 +206,7 @@ Session.create = function create(scenario) {
205206 return new Session ( { scenario : scenario } ) ;
206207} ;
207208
208- exports . saveCore = function saveCore ( options , cb ) {
209- const scenario = options . scenario ;
210- const core = options . core || exports . core ;
211-
209+ function saveCoreLLDB ( scenario , core , cb ) {
212210 // Create a core and test
213211 const sess = Session . create ( scenario ) ;
214212 sess . timeoutAfter ( exports . saveCoreTimeout ) ;
@@ -234,6 +232,47 @@ exports.saveCore = function saveCore(options, cb) {
234232 } ) ;
235233}
236234
235+ function spawnWithTimeout ( cmd , cb ) {
236+ const proc = spawn ( cmd , {
237+ shell : true ,
238+ stdio : [ 'pipe' , 'pipe' , 'pipe' ] } ) ;
239+ const stdout = new SessionOutput ( null , proc . stdout , exports . saveCoreTimeout ) ;
240+ const stderr = new SessionOutput ( null , proc . stderr , exports . saveCoreTimeout ) ;
241+ stdout . on ( 'line' , ( line ) => { debug ( '[stdout]' , line ) ; } ) ;
242+ stderr . on ( 'line' , ( line ) => { debug ( '[stderr]' , line ) ; } ) ;
243+
244+ const timeout = setTimeout ( ( ) => {
245+ console . error ( `timeout while saving core dump for scenario "${ scenario } "` ) ;
246+ proc . kill ( ) ;
247+ } , exports . saveCoreTimeout ) ;
248+
249+ proc . on ( 'exit' , ( status ) => {
250+ clearTimeout ( timeout ) ;
251+ cb ( null ) ;
252+ } ) ;
253+ }
254+
255+ function saveCoreLinux ( executable , scenario , core , cb ) {
256+ const cmd = `ulimit -c unlimited && ${ executable } ` +
257+ `--abort_on_uncaught_exception --expose_externalize_string ` +
258+ `${ path . join ( exports . fixturesDir , scenario ) } ; ` ;
259+ spawnWithTimeout ( cmd , ( ) => {
260+ // FIXME (mmarchini): Should also handle different core system settings.
261+ spawnWithTimeout ( `mv ./core ${ core } ` , cb ) ;
262+ } ) ;
263+ }
264+
265+ exports . saveCore = function saveCore ( options , cb ) {
266+ const scenario = options . scenario ;
267+ const core = options . core || exports . core ;
268+
269+ if ( process . platform === 'linux' ) {
270+ saveCoreLinux ( process . execPath , scenario , core , cb ) ;
271+ } else {
272+ saveCoreLLDB ( scenario , core , cb ) ;
273+ }
274+ }
275+
237276// Load the core dump with the executable
238277Session . loadCore = function loadCore ( executable , core , cb ) {
239278 const ranges = process . env . LLNODE_NO_RANGES ? undefined : core + '.ranges' ;
0 commit comments