linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] scripts: kerrno.sh - errno translator
@ 2015-04-30 10:53 Bartosz Golaszewski
  2015-04-30 11:04 ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2015-04-30 10:53 UTC (permalink / raw)
  To: LKML; +Cc: linux-kbuild, Bartosz Golaszewski

Shell script allowing to find errno definitions and descriptions in the
kernel source.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
This is a simple script I use when seeing messages like:

	some_func() failed: -123

to find out the actual errno meaning. The usage is very simple - just
call 'scripts/kerrno.sh 1 4 -50 (...)'.

I'm sending this as RFC in order to find out if there's any interest in merging
this script with the kernel code.

 scripts/kerrno.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100755 scripts/kerrno.sh

diff --git a/scripts/kerrno.sh b/scripts/kerrno.sh
new file mode 100755
index 0000000..ebdc8da
--- /dev/null
+++ b/scripts/kerrno.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Get preprocessor definitions and descriptions of errno numbers from the
+# Linux kernel source.
+#
+# This script parses all the C headers containing errno definitions in the
+# Linux source tree and extracts their definitions and corresponding
+# descriptions in order to quickly give users an idea on what kind of
+# an error they're dealing with.
+#
+# Example:
+#     scripts/kerrno.sh 43 -12 3
+#
+# Should be called from the top of the source tree.
+#
+# Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
+
+FILEPTRN=".*errno.*\.[ch]$"
+ERRNOPTRN="\#define[\ \t]+E[A-Z0-9]+[\ \t]+[0-9]+[\ \t]+"
+
+usage()
+{
+	echo "$0: get info for error numbers"
+	echo
+	echo "Usage:"
+	echo "\t$0 <errno numbers>"
+	echo
+	echo "\tExample: $0 -18 34 128"
+	echo
+}
+
+if [ "$#" -eq "0" ] || ([ "$#" -eq "1" ] && [ "$1" = "--help" ])
+then
+	usage
+	exit
+fi
+
+for WANTED in $@
+do
+	case ${WANTED#-} in
+		''|*[!0-9]*)
+			echo "$WANTED: not a number";
+			continue;
+			;;
+	esac
+
+	test "$WANTED" -lt "0" && WANTED=$(echo -n $WANTED | cut -d'-' -f2)
+
+	echo "Errno $WANTED:"
+	find ./ -regex "$FILEPTRN" -exec grep -nPH "$ERRNOPTRN" {} \; \
+		| tr -s ':' ' ' \
+		| tr -s '\t' ' ' \
+		| cut -d' ' -f1,2,4,5 | while read FILE LINE ERRNO NUM
+	do
+		if [ "$NUM" -eq "$WANTED" ]
+		then
+			echo -n "\t$ERRNO ("
+			echo -n "$(head $FILE -n $LINE | tail -1 | cut -d'*' -f2)"
+			echo ") defined in $FILE:$LINE"
+		fi
+	done
+done
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC] scripts: kerrno.sh - errno translator
  2015-04-30 10:53 [RFC] scripts: kerrno.sh - errno translator Bartosz Golaszewski
@ 2015-04-30 11:04 ` Richard Weinberger
  2015-04-30 11:29   ` Bartosz Golaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2015-04-30 11:04 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: LKML, linux-kbuild

On Thu, Apr 30, 2015 at 12:53 PM, Bartosz Golaszewski
<bgolaszewski@baylibre.com> wrote:
> Shell script allowing to find errno definitions and descriptions in the
> kernel source.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
> This is a simple script I use when seeing messages like:
>
>         some_func() failed: -123

What is wrong with a one-liner like:
gcc -E -dD - < include/uapi/linux/errno.h |grep -E "^#define E.* 123$"

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] scripts: kerrno.sh - errno translator
  2015-04-30 11:04 ` Richard Weinberger
@ 2015-04-30 11:29   ` Bartosz Golaszewski
  2015-04-30 12:25     ` David Sterba
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2015-04-30 11:29 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: LKML, linux-kbuild

2015-04-30 13:04 GMT+02:00 Richard Weinberger <richard.weinberger@gmail.com>:
> On Thu, Apr 30, 2015 at 12:53 PM, Bartosz Golaszewski
> <bgolaszewski@baylibre.com> wrote:
>> Shell script allowing to find errno definitions and descriptions in the
>> kernel source.
>>
>> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>> ---
>> This is a simple script I use when seeing messages like:
>>
>>         some_func() failed: -123
>
> What is wrong with a one-liner like:
> gcc -E -dD - < include/uapi/linux/errno.h |grep -E "^#define E.* 123$"

Nothing really - the output is less nice, that's all.

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] scripts: kerrno.sh - errno translator
  2015-04-30 11:29   ` Bartosz Golaszewski
@ 2015-04-30 12:25     ` David Sterba
  2015-04-30 12:33       ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2015-04-30 12:25 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Richard Weinberger, LKML, linux-kbuild

On Thu, Apr 30, 2015 at 01:29:41PM +0200, Bartosz Golaszewski wrote:
> 2015-04-30 13:04 GMT+02:00 Richard Weinberger <richard.weinberger@gmail.com>:
> > On Thu, Apr 30, 2015 at 12:53 PM, Bartosz Golaszewski
> > <bgolaszewski@baylibre.com> wrote:
> >> Shell script allowing to find errno definitions and descriptions in the
> >> kernel source.
> >>
> >> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >> ---
> >> This is a simple script I use when seeing messages like:
> >>
> >>         some_func() failed: -123
> >
> > What is wrong with a one-liner like:
> > gcc -E -dD - < include/uapi/linux/errno.h |grep -E "^#define E.* 123$"
> 
> Nothing really - the output is less nice, that's all.

I'd find a helper script useful in situations where I don't know the
error code immediatelly and have to convert it from a hexa value first.
Eg. when RAX contains an error code after a BUG_ON:

RAX: 00000000ffffffe4

this translates to -28 == -ENOSPC.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] scripts: kerrno.sh - errno translator
  2015-04-30 12:25     ` David Sterba
@ 2015-04-30 12:33       ` Richard Weinberger
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Weinberger @ 2015-04-30 12:33 UTC (permalink / raw)
  To: dsterba, Bartosz Golaszewski, LKML, linux-kbuild

Am 30.04.2015 um 14:25 schrieb David Sterba:
> On Thu, Apr 30, 2015 at 01:29:41PM +0200, Bartosz Golaszewski wrote:
>> 2015-04-30 13:04 GMT+02:00 Richard Weinberger <richard.weinberger@gmail.com>:
>>> On Thu, Apr 30, 2015 at 12:53 PM, Bartosz Golaszewski
>>> <bgolaszewski@baylibre.com> wrote:
>>>> Shell script allowing to find errno definitions and descriptions in the
>>>> kernel source.
>>>>
>>>> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>>> ---
>>>> This is a simple script I use when seeing messages like:
>>>>
>>>>         some_func() failed: -123
>>>
>>> What is wrong with a one-liner like:
>>> gcc -E -dD - < include/uapi/linux/errno.h |grep -E "^#define E.* 123$"
>>
>> Nothing really - the output is less nice, that's all.
> 
> I'd find a helper script useful in situations where I don't know the
> error code immediatelly and have to convert it from a hexa value first.
> Eg. when RAX contains an error code after a BUG_ON:
> 
> RAX: 00000000ffffffe4
> 
> this translates to -28 == -ENOSPC.

You mean a script where you can pipe a register dump into and it tries to
translate all registers values to meaningful values?
Yes, that would be nice... :)

Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-04-30 12:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-30 10:53 [RFC] scripts: kerrno.sh - errno translator Bartosz Golaszewski
2015-04-30 11:04 ` Richard Weinberger
2015-04-30 11:29   ` Bartosz Golaszewski
2015-04-30 12:25     ` David Sterba
2015-04-30 12:33       ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).