Pass variable name as a string to task in verilog
You can make a macro to do this instead of a task

`define debug_message(Var,Value) \
begin \
  Var = Value; \
  $display("The variable name is %s and its value is %d", `"Var`", Var); \
end


A macro treats its arguments as just text, giving you the ability to reinterpret them as identifiers or strings. The `" instead of " is what lets lets you have macro arguments inside a string.