GDBMITrace.st
author Jan Vrany <jan.vrany@labware.com>
Mon, 04 Sep 2023 14:00:57 +0100
changeset 314 4a2ef5a087f0
parent 309 f2481d09d58e
permissions -rw-r--r--
Add MI parser test This commit add test to parse real-world frament which failed to Pharo properly at some point. It is encoded here as bytearray to make sure all the characters are preserved exactly as they were.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

OrderedCollection subclass:#GDBMITrace
	instanceVariableNames:'lock'
	classVariableNames:''
	poolDictionaries:''
	category:'GDB-Internal-MI Trace'
!

!GDBMITrace class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
! !

!GDBMITrace class methodsFor:'instance creation'!

new
    ^ super new initialize.

    "Created: / 24-06-2014 / 00:07:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

new: size
    "return an initialized instance"

    ^ (super new: size) initialize.

    "Created: / 24-06-2014 / 00:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMITrace methodsFor:'adding & removing'!

add:anObject
    "add the argument, anObject to the end of the collection
     Return the argument, anObject."

    ^ lock critical:[ 
        super add:anObject
    ].

    "Modified: / 29-01-1998 / 10:52:32 / cg"
    "Modified: / 23-06-2014 / 23:55:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

add:anObject beforeIndex:index
    "add the argument, anObject to the end of the collection.
     Return the receiver (sigh - ST-80 compatibility)."

    ^ lock critical:[ 
        super add:anObject beforeIndex:index
    ].

    "Modified: / 23-06-2014 / 23:55:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addAll:aCollection beforeIndex:index
    "insert all elements of the argument
     Return the receiver."

    ^ lock critical:[ 
        super addAll:aCollection beforeIndex:index      
    ].

    "Modified: / 23-06-2014 / 23:55:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addAllLast:aCollection
    "add all elements of the argument, aCollection to the end of the collection.
     Return the argument, aCollection."

    ^ lock critical:[ 
        super addAllLast:aCollection       
    ].

    "Modified: / 23-06-2014 / 23:56:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addFirst:anObject
    "add the argument, anObject to the beginning of the collection.
     Return the argument, anObject."

     ^ lock critical:[ 
        super addFirst:anObject
    ].

    "Modified: / 29-01-1998 / 10:53:09 / cg"
    "Modified: / 23-06-2014 / 23:56:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMITrace methodsFor:'initialization'!

initialize
    "Invoked when a new instance is created."

    "/ please change as required (and remove this comment)
    super initialize.
    lock := GDBPortlib current newMutex.

    "/ super initialize.   -- commented since inherited method does nothing

    "Modified: / 24-06-2014 / 00:05:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-08-2023 / 15:51:41 / Jan Vrany <jan.vrany@labware.com>"
! !

!GDBMITrace methodsFor:'printing & storing'!

printOn:aStream
    self do:[:each | each printOn: aStream ]

    "Modified: / 23-06-2014 / 23:51:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMITrace methodsFor:'recording'!

<<< aString 
    self add:(GDBMITraceResponseRecord new string:aString)
!

>>> aString 
    self add:(GDBMITraceCommandRecord new string:aString)
! !

!GDBMITrace methodsFor:'saving & restoring'!

saveInClass: class selector: selector
    "Save recorded session in given class under given selector"

    | source |

    source := String new writeStream.
    source nextPutAll: selector; cr; cr.
    source nextPutAll:' ^ (GDBSessionRecord new: '.
    self size printOn: source.
    source nextPutAll: ')'; cr; cr.

    self do:[:each | 
        each isCommand ifTrue:[ 
            source nextPutLine: '>>>'.
        ] ifFalse:[
            source nextPutLine: '<<<'.
        ].
        each string storeOn: source.
        source nextPut: $;; cr; cr.  
    ].
    source nextPutAll: 'yourself'.

    class compile: source contents classified: 'recorded sessions'

    "Created: / 23-06-2014 / 23:14:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 24-06-2014 / 00:44:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

saveInSimulatorResourceAs: selector
    ^ self saveInClass: GDBSimulatorResource selector: selector

    "Created: / 23-06-2014 / 23:17:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !