Bug 22671 - MIPSEL error Unknown register: a4
Summary: MIPSEL error Unknown register: a4
Status: RESOLVED WONTFIX
Alias: None
Product: systemtap
Classification: Unclassified
Component: runtime (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-04 06:42 UTC by Gustavo Moreira
Modified: 2023-12-06 15:31 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2018-02-26 00:00:00


Attachments
kernel config (35.76 KB, text/plain)
2018-01-04 06:42 UTC, Gustavo Moreira
Details
Simple mips patch (384 bytes, patch)
2018-01-15 18:31 UTC, David Smith
Details | Diff
MIPS o32 ABI patch (1.20 KB, patch)
2018-04-26 07:50 UTC, Gustavo Moreira
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo Moreira 2018-01-04 06:42:45 UTC
Created attachment 10711 [details]
kernel config

Having this error on mipsel emulation: 
...
stapio:stp_main_loop:861 systemtap_module_init() returned 0
ERROR: Unknown register: a4
stapio:stp_main_loop:852 got STP_REQUEST_EXIT
WARNING: Number of errors: 1, skipped probes: 0
stapio:stp_main_loop:841 got STP_EXIT
stapio:cleanup_and_exit:526 detach=0
...


# stap --version
Systemtap translator/driver (version 3.2/0.168, non-git sources)
Copyright (C) 2005-2017 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
tested kernel versions: 2.6.18 ... 4.11
enabled features: AVAHI LIBSQLITE3 NLS NSS

# uname -a
Linux arex-11f9b261f2 4.9.0-4-4kc-malta #1 Debian 4.9.65-3 (2017-12-03) mips GNU/Linux

The Rootfs is a Debian Stretch.

It seems to be an ABI (O32/N32) issue, but not sure why it's happening. I've locally compiled SystemTap from Systemtap 3.2 release (https://sourceware.org/systemtap/ftp/releases/systemtap-3.2.tar.gz)

Any clue?
Comment 1 David Smith 2018-01-05 14:25:09 UTC
(In reply to Gustavo Moreira from comment #0)
> Created attachment 10711 [details]
> kernel config
> 
> Having this error on mipsel emulation: 
> ...
> stapio:stp_main_loop:861 systemtap_module_init() returned 0
> ERROR: Unknown register: a4

It looks like this is coming from tapset/mips/registers.stp. It appears that that file has only been tested against 64-bit kernels. It doesn't think the a4-a7 registers exist in a 32-bit kernel. That prevents it from grabbing the 5th through 8th argument to a function (in _stp_arg()).

If you know the calling convention for a 32-bit mips kernel, we can fix that file.
Comment 2 Gustavo Moreira 2018-01-08 00:43:42 UTC
It seems a4-a7 registers exist in n32 but not in o32.
Debian uses o32, so it seems SystemTap struggles to detect the ABI or it just uses n32 by default.
The kernel is a prebuilt one. I got it from (http://ftp.debian.org/debian/dists/stretch/main/installer-mipsel/current/images/malta/netboot/vmlinux-4.9.0-4-4kc-malta)

I've extracted the .config file from kernel and I've attached it to this ticket.
Comment 3 David Smith 2018-01-15 18:31:31 UTC
Created attachment 10751 [details]
Simple mips patch

Here's a simple (untested) patch that will get you past your initial error message and allow you to access the first 4 arguments of a function. To access the rest, someone with knowledge of the 32-bit MIPS ABI (and access to MIPS hardware) will need to write some code that decodes the MIPS o32 user and kernel stacks.
Comment 4 David Smith 2018-01-26 21:26:45 UTC
I went ahead and checked in this patch as commit 1d0a3dc015c.
Comment 5 Gustavo Moreira 2018-02-26 03:48:45 UTC
(In reply to David Smith from comment #3)
> Created attachment 10751 [details]
> Simple mips patch
> 
> Here's a simple (untested) patch that will get you past your initial error
> message and allow you to access the first 4 arguments of a function. To
> access the rest, someone with knowledge of the 32-bit MIPS ABI (and access
> to MIPS hardware) will need to write some code that decodes the MIPS o32
> user and kernel stacks.

Actually, I've replaced the final FIXME assert() with error() instead, otherwise it raises another compilation error. Anyway, the assert() function executes error() so it should be equivalent:
  error(sprintf("Cannot access arg(%d)", argnum))

But yeah it would be needed to write some code to fix it completely.
Comment 6 David Smith 2018-02-26 22:08:25 UTC
(In reply to Gustavo Moreira from comment #5)
> But yeah it would be needed to write some code to fix it completely.

If you have the time to figure this out, go ahead and send us a patch. We'll be happy to review it and check it in for you.
Comment 7 Gustavo Moreira 2018-04-26 07:50:14 UTC
Created attachment 10988 [details]
MIPS o32 ABI patch

This is based on arch/mips/include/ptrace.h and ARM registers.stp.
However, it doesn't seem to be working correctly, the values extracted from the user stack, for some reason, aren't the correct ones. 
I would appreciate if you can review the patch and help me out.
Comment 8 Frank Ch. Eigler 2018-04-26 20:59:02 UTC
Merged that patch (slightly adjusted).
Sorry, I am not sure what to do with the userspace registers, though there should be a user-side pt_regs struct with a saved register dump available.
Comment 9 William Cohen 2023-12-06 15:31:02 UTC
Don't have any access to MIPS machines, so it is unlikely that we will be able to address this further.