Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

### v0.7.1 (NOT YET RELEASED)
* Additions
* ...
* Added a function that prints information about the heap for debugging purposes (`debugHeap` in cx/utilities.go).
* Changes
* ...
* Libraries
* ...
* Fixed issues
* ...
* #286: Compilation error when struct field is named 'input' or 'output'
* #323: Installation issues on Windows after merging #320
* Documentation
* ...
* Miscellaneous
Expand Down
12 changes: 12 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ ignored = ["github.com/go-gl/*"]
[prune]
go-tests = true
unused-packages = true

[[constraint]]
branch = "master"
name = "github.com/sn-srdjan/cx-tracker-cli"
6 changes: 3 additions & 3 deletions cx-setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ if %ERRORLEVEL% neq 0 (


rem run CX tests
%BIN_PATH%\cx.exe %SKYCOIN_PATH%\cx\tests
%BIN_PATH%\cx.exe %SKYCOIN_PATH%\cx\tests\main.cx ++wdir=tests\ ++disable-tests=gui,issue
call :showResults cx\tests "Tested" "ERROR while testing"

call :echoWithColor yellow "You can re-run CX tests with:"
Expand Down Expand Up @@ -235,10 +235,10 @@ exit /b
%BIN_PATH%\goyacc -o %CXGO_PATH%\cxgo0\cxgo0.go %CXGO_PATH%\cxgo0\cxgo0.y
call :showResults "goyacc cxgo0" "1st pass -" "ERROR in 1st pass -"

%BIN_PATH%\nex -e %CXGO_PATH%\cxgo.nex
%BIN_PATH%\nex -e %CXGO_PATH%\parser\cxgo.nex
call :showResults "nex cxgo" "2nd pass -" "ERROR in 2nd pass -"

%BIN_PATH%\goyacc -o %CXGO_PATH%\cxgo.go %CXGO_PATH%\cxgo.y
%BIN_PATH%\goyacc -o %CXGO_PATH%\parser\cxgo.go %CXGO_PATH%\parser\cxgo.y
call :showResults "goyacc cxgo" "2nd pass -" "ERROR in 2nd pass -"


Expand Down
4 changes: 2 additions & 2 deletions cx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ if [ ! $? -eq 0 ]; then
exit 0
fi

$INSTALLATION_PATH/bin/nex -e $INSTALLATION_PATH/src/github.com/skycoin/cx/cxgo/cxgo.nex
$INSTALLATION_PATH/bin/nex -e $INSTALLATION_PATH/src/github.com/skycoin/cx/cxgo/parser/cxgo.nex
if [ ! $? -eq 0 ]; then
echo "FAIL:\tThere was a problem compiling CX's lexical analyzer"
exit 0
fi

$INSTALLATION_PATH/bin/goyacc -o $INSTALLATION_PATH/src/github.com/skycoin/cx/cxgo/cxgo.go $INSTALLATION_PATH/src/github.com/skycoin/cx/cxgo/cxgo.y
$INSTALLATION_PATH/bin/goyacc -o $INSTALLATION_PATH/src/github.com/skycoin/cx/cxgo/parser/cxgo.go $INSTALLATION_PATH/src/github.com/skycoin/cx/cxgo/parser/cxgo.y
if [ ! $? -eq 0 ]; then
echo "FAIL:\tThere was a problem compiling CX's parser"
exit 0
Expand Down
83 changes: 83 additions & 0 deletions cx/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"runtime/debug"
"strconv"
"text/tabwriter"

"github.com/amherag/skycoin/src/cipher/encoder"
)
Expand Down Expand Up @@ -994,3 +995,85 @@ func mustDeserializeRaw(byts []byte, item interface{}) {
panic(err)
}
}

// DebugHeap prints the symbols that are acting as pointers in a CX program at certain point during the execution of the program along with the addresses they are pointing. Additionally, a list of the objects in the heap is printed, which shows their address in the heap, if they are marked as alive or as dead by the garbage collector, the address where they used to live after a garbage collector call, the full size of the object, the object itself as a slice of bytes and the pointers that are pointing to that object.
func DebugHeap() {
// symsToAddrs will hold a list of symbols that are pointing to an address.
symsToAddrs := make(map[int32][]string)

// Processing global variables. Adding the address they are pointing to.
for _, pkg := range PROGRAM.Packages {
for _, glbl := range pkg.Globals {
if glbl.IsPointer || glbl.IsSlice {
var heapOffset int32
_, err := encoder.DeserializeAtomic(PROGRAM.Memory[glbl.Offset:glbl.Offset+TYPE_POINTER_SIZE], &heapOffset)
if err != nil {
panic(err)
}

symsToAddrs[heapOffset] = append(symsToAddrs[heapOffset], glbl.Name)
}
}
}

// Processing local variables in every active function call in the `CallStack`.
// Adding the address they are pointing to.
var fp int
for c := 0; c <= PROGRAM.CallCounter; c++ {
op := PROGRAM.CallStack[c].Operator

// TODO: Some standard library functions "manually" add a function
// call (callbacks) to `PRGRM.CallStack`. These functions do not have an
// operator associated to them. This can be considered as a bug or as an
// undesirable mechanic.
// [2019-06-24 Mon 22:39] Actually, if the GC is triggered in the middle
// of a callback, things will certainly break.
if op == nil {
continue
}

for _, ptr := range op.ListOfPointers {
var heapOffset int32
_, err := encoder.DeserializeAtomic(PROGRAM.Memory[fp+ptr.Offset:fp+ptr.Offset+TYPE_POINTER_SIZE], &heapOffset)
if err != nil {
panic(err)
}

symsToAddrs[heapOffset] = append(symsToAddrs[heapOffset], ptr.Name)
}

fp += op.Size
}

// Printing all the details.
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, '.', 0)

for off, symNames := range symsToAddrs {
addrB := encoder.Serialize(off)
fmt.Fprintln(w, "Addr:\t", addrB, "\tPtr:\t", symNames)
}

// Just a newline.
fmt.Fprintln(w)
w.Flush()

w = tabwriter.NewWriter(os.Stdout, 0, 0, 2, '.', 0)

for c := PROGRAM.HeapStartsAt + NULL_HEAP_ADDRESS_OFFSET; c < PROGRAM.HeapStartsAt+PROGRAM.HeapPointer; {
var objSize int32
_, err := encoder.DeserializeAtomic(PROGRAM.Memory[c+MARK_SIZE+FORWARDING_ADDRESS_SIZE:c+MARK_SIZE+FORWARDING_ADDRESS_SIZE+OBJECT_SIZE], &objSize)
if err != nil {
panic(err)
}

addrB := encoder.Serialize(int32(c))

fmt.Fprintln(w, "Addr:\t", addrB, "\tMark:\t", PROGRAM.Memory[c:c+MARK_SIZE], "\tFwd:\t", PROGRAM.Memory[c+MARK_SIZE:c+MARK_SIZE+FORWARDING_ADDRESS_SIZE], "\tSize:\t", objSize, "\tObj:\t", PROGRAM.Memory[c+OBJECT_HEADER_SIZE:c+int(objSize)], "\tPtrs:", symsToAddrs[int32(c)])

c += int(objSize)
}

// Just a newline.
fmt.Fprintln(w)
w.Flush()
}
2 changes: 0 additions & 2 deletions cxgo/cxgo0/cxgo0.nex
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
/clauses/ { return f(CLAUSES) }
/def/ { return f(DEF) }
/field/ { return f(FIELD) }
/input/ { return f(INPUT) }
/output/ { return f(OUTPUT) }
/import/ { return f(IMPORT) }
/var/ { return f(VAR) }
/"([^"]*)"/ { /* " */
Expand Down
2 changes: 1 addition & 1 deletion cxgo/cxgo0/cxgo0.y
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
/* Selectors */
SPACKAGE SSTRUCT SFUNC
/* Removers */
REM DEF EXPR FIELD INPUT OUTPUT CLAUSES OBJECT OBJECTS
REM DEF EXPR FIELD CLAUSES OBJECT OBJECTS
/* Stepping */
STEP PSTEP TSTEP
/* Debugging */
Expand Down
Loading