Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ndk-gdb fails with -f #1764

Closed
jfgoog opened this issue Sep 9, 2022 · 6 comments
Closed

[BUG] ndk-gdb fails with -f #1764

jfgoog opened this issue Sep 9, 2022 · 6 comments
Labels

Comments

@jfgoog
Copy link
Collaborator

jfgoog commented Sep 9, 2022

Description

When running ndk-gdb -f:

Traceback (most recent call last):
  File "/home/marijn/Android/Sdk/ndk/25.1.8937393/prebuilt/linux-x86_64/bin/ndk-gdb.py", line 951, in <module>
    main()
  File "/home/marijn/Android/Sdk/ndk/25.1.8937393/prebuilt/linux-x86_64/bin/ndk-gdb.py", line 882, in main
    device.shell_nocheck(["run-as", pkg_name, "kill", "-9"] + kill_pids)
TypeError: can only concatenate list (not "map") to list

Affected versions

r25

Canary version

No response

Host OS

Windows

Host OS version

n/a

Affected ABIs

armeabi-v7a, arm64-v8a, x86, x86_64

Build system

Other (specify below)

Other build system

No response

minSdkVersion

n/a

Device API level

No response

@jfgoog jfgoog added the bug label Sep 9, 2022
@MarijnS95
Copy link

MarijnS95 commented Sep 9, 2022

This is another Python 2 -> Python 3 conversion problem just like #1763:

The current code is as follows:

        kill_pids = map(str, kill_pids)
        if kill_pids:
            log("Killing processes: {}".format(", ".join(kill_pids)))
            device.shell_nocheck(["run-as", pkg_name, "kill", "-9"] + kill_pids)

In Python 2, map() returns a list which you can freely concatenate to another list. In Python 3 map() returns a lazy map object (a generator) and can't be immediately concatenated to a list. Besides, map() is discouraged in favour of generator expressions, or in this specific case a list comprehension:

kill_pids = [str(pid) for pid in kill_pids]

EDIT: You can however also use some_list.extend(<iterable, i.e. generator>) to let the list iterate a generator and append every individual item to itself.

@DanAlbert
Copy link
Member

Whoever fixes this should extend our pylint check over this script. Pylint would have caught this.

@DanAlbert
Copy link
Member

@appujee has uploaded a fix here: https://android-review.git.corp.google.com/c/platform/ndk/+/2579812 (thanks!)

Will leave the bug open for myself to extend pylint coverage and to update the changelog.

@MarijnS95
Copy link

https://r.android.com/c/platform/ndk/+/2579812 link for non-Googlers.

There's actually a nicer way to write this now, using the splat operator to expand one array within another array:

        kill_pids = [str(pid) for pid in kill_pids]
        if kill_pids:
            log("Killing processes: {}".format(", ".join(kill_pids)))
            device.shell_nocheck(["run-as", pkg_name, "kill", "-9", *kill_pids])

(Notice the splat operator on the last line)


Regarding pylint, I've seen some of the many Python linters recommend using the splat operator over +.

@DanAlbert
Copy link
Member

https://r.android.com/c/platform/ndk/+/2579812 link for non-Googlers.

Ugh. Sorry. A while ago someone decided that my URL bar should be rewritten to something useless. I don't always remember to rewrite it by hand before pasting.

@DanAlbert
Copy link
Member

The fix for this appears to have been in r26 beta 1 and I just forgot to add it to the changelog. In any case it's certainly in RC 1 (and I've updated the changelog).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Merged
Development

No branches or pull requests

4 participants
@DanAlbert @MarijnS95 @jfgoog and others