This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How can I access ULONG_MAX constant without using -g option?


Well, it seems to me that below change fixes my problem.

--- systemtap/tapset/linux/task.stp
+++ systemtap/tapset/linux/task.stp
@@ -29,7 +29,7 @@
  * more task-specific data.
  */
 function task_current:long () %{ /* pure */
-    STAP_RETVALUE = (long)current;
+    STAP_RETVALUE = (unsigned long)current;
 %}
 
 /**

It seems to me that STAP_RETVALUE is treated as "long long" (64bits) variable
and assigning a "long" (32bits) value to STAP_RETVALUE variable triggers
sign-extension. This sign-extension can be suppressed by casting to
"unsigned long" instead of "long".

This problem seems to exist in whatever functions (e.g. pid2task()) which
return address as long via "STAP_RETVALUE = (long)some_pointer_variable;".
I think that functions which return address should suppress sign-extension.

Tetsuo Handa wrote:
> Hello.
> 
> I'm using systemtap-2.3-4.el6_5.i686 and I need to mask a value with ULONG_MAX
> constant because task_current() returns 64bits value on 32bits architecture.
> 
>   # uname -m
>   i686
>   # stap -e 'probe begin { printf("current=%lx\n", task_current()); exit(); }'
>   current=ffffffffc1681aa0
> 
> In the example output above, current=c1681aa0 is the expected value on i686.
> 
> I know I can wrap like
> 
>   function get_current:long() {
>     return task_current() & %{ ULONG_MAX %};
>   }
> 
> and use get_current() instead of task_current(), but this needs -g option.
> Is there a way to do it without using -g option?
> 
> Regards.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]