When I run a particular Tcl script with my Vivado project, I always get a crash. The commands I am using seem typical and the system is not running out of memory or other resources.
What could be wrong?
Below are some of the known causes of exceptions due to the way a Tcl is constructed.
These are issues you might run into when writing what appears to be a valid Tcl script.
Referencing objects in a Tcl list after closing a design or a project can lead to a Vivado crash.
The following small script will crash Vivado.
The issue here is that [get_cells] returns an optimized list of cells where each individual list element is a raw C++ pointer as opposed to a Tcl_Obj.
When the design or project is closed, the Vivado netlist objects are destroyed and the 'cells' variable now has a list of bad C++ pointers.
Relying on the string representation of a collection is not safe.
The string representation of a Tcl collection is truncated to the first 500 (default via parameter) elements of the collection.
This violates Tcl's basic Every-Is-A-String principle (EIAS) and certain native Tcl commands that rely exclusively on the string representation of a Tcl Object might not work as expected when the number of elements in the collection exceeds 500.
An example of a possibly bad Tcl string command is shown here:
The string command relies on the string representation of the collection returned by get_tiles, but that representation only reflects the first 500 element of the collection.
Beware of commands that convert a collection into a Tcl list.
The RDI Tcl infrastructure overrides all list commands so that they transparently handle Tcl collections just as if they were Tcl lists.
However, there are few list commands, where the override simply converts the Tcl collection into a Tcl list and then uses Tcl's native list command on the resulting Tcl list. This is safe by construction, but depending on the number of elements in the collection the conversion is not always efficient.
A collection is one Tcl Object (Tcl_obj) wrapping a C++ container of native objects. A Tcl list is a Tcl Object pointing to a linked list of Tcl Objects, one for each element in the list.
So for example, a million objects can be easily represented in a Tcl collection with all but one Tcl Object, but when/if expanded into a Tcl list there will be a million +1 Tcl Objects, which will likely cause the Tcl software to have issues such as performance degradation or crash.
The most commonly used command that convert a Tcl collection into a Tcl list is Tcl's lsort command.
Vivado Tcl infrastructure provides no native implementation of lsort because that command was deemed overly complex and a native implementation would still face run-time issues when it would have to compute the string representation of each element in the collection before sorting.
It is not clear that overriding lsort would provide any value beyond saving memory.
Here are the list commands that convert the collection into a Tcl list before doing the work: