Cocotb: System-call implementations do not handle format values

Created on 13 May 2014  路  6Comments  路  Source: cocotb/cocotb

We've overloaded $error etc to allow us to provide a consistent logging mechanism.

Unfortunately this implementation doesn't handle format values appropriately.

bug

All 6 comments

Looks like we need to pull off all the values from the args_iter, then create a msg from this to pass to gpi_log. Since this is not speed critical code I don't see a problem with this two stage printing.

Thought some more and I plan on doing this.

Split the gpi_log into gpi_log/gpi_logf, first just takes a string the second a format string. The format string for from vpi/vhpi is then handled in the implementation layer by iterating over the args and then calling vasprintf on those. And calling gpi_log with the string.

Where the whole list is known at the callsite the caller can call gpi_log.

Hi, I see this hasn't ticket hasn't had any activity in some time. We recently came across this issue while helping a customer with a COCOTB environment. Is there any plan to still address this issue? In the interim, is there any workaround to circumvent the overloading? Thanks! Eric Mackie (Mentor Graphics)

Hi Stuart,
Any updates on this issue? This is actually a show stopper for our sim environment. We are unable to upgrade the Modelsim version because of this bug. And the new Modelsim version has the features that we need.

Thanks,
Richard

It looks to me like this is unfortunately going to be a more involved fix than handling the arguments over to vasprintf .

Issues:

  • verilog $display type functions support verilog specific format characters like %m (hierarchical name) and and %T (simulation time).
  • As part of iterating over the vpiArgument we'll need to do the same Verilog to C type conversion of the arguments that a simulator would have to do.
  • It's not obvious to me how we can get the runtime iterated arguments into va_list to hand off for formatting.

So I think we'll need to implement the string interpolation/formatting ourselves similar to what a simulator would do if it were handling the call to $info, $error, etc.

I can work on this but, as it's a non trivial amount of new code, I wanted to run it by the list to see if anyone had a better idea.

We might have to port the extremely heavyweight implementation of get_display from iverilog:

https://github.com/steveicarus/iverilog/blob/9d0d1938dc66b715b1ac6693913a9e79d3cb401c/vpi/sys_display.c#L960-L1137

@pgfarley I think your last point is a non-issue, it can be solved with code like:

// this doesn't use C varargs, but VPI iteration
char *str = format_using_verilog_semantics(args_from_vpi);

// no formatting or varargs needed here
gpi_log(..., "%s", str);

free(str);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexforencich picture alexforencich  路  5Comments

elgorwi picture elgorwi  路  9Comments

ktbarrett picture ktbarrett  路  8Comments

raysalemi picture raysalemi  路  3Comments

ktbarrett picture ktbarrett  路  9Comments