The get_arg_value function in uvm_cmdline_proc seems to have a non-intuitive ref string value update. In case there is no match, I would expect the value string to be an empty string. But what happens is that it retains its last value. Why wouldn’t the function simply return an empty string allowing us to reuse the variable?
Below is the relevant code
// Function: get_arg_value
//
// This function finds the first argument which matches the ~match~ arg and
// returns the suffix of the argument. This is similar to the $value$plusargs
// system task, but does not take a formatting string. The return value is
// the number of command line arguments that match the ~match~ string, and
// ~value~ is the value of the first match.
function int get_arg_value (string match, ref string value);
int chars = match.len();
get_arg_value = 0;
foreach (m_argv[i]) begin
if(m_argv[i].len() >= chars) begin
if(m_argv[i].substr(0,chars-1) == match) begin
get_arg_value++;
if(get_arg_value == 1)
value = m_argv[i].substr(chars,m_argv[i].len()-1);
end
end
end
endfunction